home *** CD-ROM | disk | FTP | other *** search
/ The Complete Utilities To…ka 501 Killer Utilities! / 501 Killer Utilities! (Macworld July 1995).cdr / Programming / Tools Plus 2.5.3 Evaluation Kit / Tools Plus 2.5.3 / Demos / Demo for THINK C⁄C++ / Demo.c next >
Encoding:
Text File  |  1994-12-12  |  179.6 KB  |  3,266 lines  |  [TEXT/KAHL]

  1. /***********************************************************************************
  2.  *    Tools Plus    --    D e m o   P r o g r a m    --    (Version 2.5.3)
  3.  *    Copyright (c) 1994-95 Water's Edge Software
  4.  *    Designed and programmed by Steve Makohin
  5.  *
  6.  *    All files in this project use the Monaco 9pt.
  7.  *    This application is written as a single source file (ie: I deliberately did NOT
  8.  *    split it into units) to simplify compiling for programmers that are just
  9.  *    starting out.  It also demonstrates that programming with Tools Plus makes
  10.  *    source code compact and readable.
  11.  *
  12.  *    If you are put off by the size of this program, please note that it is
  13.  *    H E A V I L Y   C O M M E N T E D and it is not optimized, both of which were
  14.  *    done to facilitate the teaching of Tools Plus.
  15.  *
  16.  *    Though you will likely be able to figure out what each line of source code does,
  17.  *    extensive comments are provided so you won't have to constantly refer to the
  18.  *    Tools Plus User Manual and Inside Macintosh.
  19.  
  20.  
  21.  *    D e b u g g e r:
  22.  *    Make sure you allocate sufficient memory to the debugger (350K or more). That
  23.  *    memory is needed to handle this large source file.
  24.  
  25.  
  26.  *    G e t t i n g   S o m e w h e r e   F a s t :
  27.  *    To view a list of routines found in this demo, hold the Command key down while
  28.  *    clicking in this window's title bar. A pop-down menu is displayed showing you
  29.  *    the routines' names. You can use this pop-down menu to quickly go to a specific
  30.  *    routine.
  31.  
  32.  
  33.  *    R e s o u r c e s :
  34.  *    This demo uses resources that can be found in the "Demo Resources" file.  The
  35.  *    following describes each of the resources and what function they perform in this
  36.  *    application.  You can add, change, delete and view resources by using a resource
  37.  *    editor application such as Apple's ResEdit.
  38.  *
  39.  *    Type     ID    Description
  40.  *    ----  -------  -----------
  41.  *    acur        128       Animated Cursor definition:  Tells Tools Plus how to animate the
  42.  *                 cursor to create a wrist watch with a spinning second hand.  The
  43.  *                 'acur' resource specifies the sequence of cursor resources
  44.  *                 ('CURS') that will be used for the animation, and the time taken
  45.  *                 between steps.  See the User Manual for details.
  46.  *
  47.  *    BNDL        128    Bundle Resource:  This resource tells the Finder which icons are
  48.  *                 used to depict the application and the documents created by it.
  49.  *                 The BNDL resource bundles the following related resources: FREF,
  50.  *                 icl4, icl8, ICN#, and 'TP 1'
  51.  *
  52.  *    cicn        - -         Color Icons (definable size):  This is the first color icon format
  53.  *                                 available on color (Mac II) Macintoshes.  Each 'cicn' includes a
  54.  *                                 color image, the equivalent black and white image, and a mask.  In
  55.  *                                 this demo, all 'cicn' icons were created using 4-bit colors to
  56.  *                                 ensure that they look good when displayed on monitors set to
  57.  *                                 16-colors/grays or higher.
  58.  *                300-303  These color icons (hard disk, floppy, and folder) show up in the
  59.  *                                 Pop-Up Menus demo beside menu item names.
  60.  *                304,305     These "large" color icons (printer and modem) appear in "picture
  61.  *                                 Pop-Up Menus" (picture in a Pop-Up Menu without any text).  There
  62.  *                                 are 'ICON' equivalents for these items for Macs without Color
  63.  *                                 QuickDraw.
  64.  *                430-441     These "tape deck" buttons are used in the Picture Buttons demo to
  65.  *                                 show you the look you can get with Tools Plus's buttons.  Each
  66.  *                                 button requires two icons, one for the button's normal state, and
  67.  *                                 one for the selected (pushed in) state.  I know, they don't behave
  68.  *                                 like a real tape deck, but this is only a demo.
  69.  *                460,461  This bi-directional "globe" button is used in the Picture Buttons
  70.  *                                 demo.  The two icons show the button in its normal state, and in
  71.  *                                 its selected (pushed in) state.
  72.  *                464,465     This "Done" button is used in the Picture Buttons demo.  The two
  73.  *                                 icons show the button in its normal state, and in its selected
  74.  *                                 (pushed in) state.  Even the most ordinary buttons can look
  75.  *                                 sophisticated with Tools Plus.
  76.  *                520-541     These are all used in the Floating Palettes demo to create
  77.  *                                 clickable icons.  You can create professional looking palettes
  78.  *                                 with various styles of buttons using Tools Plus.
  79.  *
  80.  *    CURS    128-134  Cursors:  These cursors are used to produce an animated cursor.
  81.  *                 The 'acur' resource specified which cursors are used, and the
  82.  *                 animation's speed.  See the User Manual for details.
  83.  *
  84.  *    FREF        128    Finder Reference:  This resource is automatically created when a
  85.  *                 BNDL resource is created.  One FREF exists for each icon that the
  86.  *                 Finder references.  This demo is an application (file type is
  87.  *                 'APPL'), so one FREF is needed for that.  If this demo had the
  88.  *                 ability to create three different kinds of documents, then one
  89.  *                 FREF would be required for each kind type of document.
  90.  *
  91.  *    icl4        - -         Large (32x32 pixel) 4-bit Icons:  These icons are typically used
  92.  *                 only by the Finder to depict an application and its related
  93.  *                 files.  However, your application can also draw these icons with
  94.  *                 Tools Plus.  4-bit icons can have a maximum of 16 colors.
  95.  *                    0,1,2     These "large" color icons appear in "picture Pop-Up Menus"
  96.  *                                 (picture in a Pop-Up Menu without any text).  There are 'ICON'
  97.  *                                 equivalents for these items for Macs without Color QuickDraw.
  98.  *                                 These color icons will be used on color monitors as a substitute
  99.  *                 for the system's Stop, Note and Caution icons.  They give color
  100.  *                 applications a better look.
  101.  *                    128         Application's Icon (displayed by the Finder.  The BNDL resource
  102.  *                 refers to this icon)
  103.  *                    150         Printer icon used to demonstrate drawing icon families
  104.  *                    151         Modem icon used to demonstrate drawing icon families
  105.  *                400,401     Left Arrow button used in Picture Buttons demo (part of an icl8 /
  106.  *                                 icl4 / ICN# family).  One icon is used for the button's standard
  107.  *                                 position, and another for the selected (pushed in) position.
  108.  *                402,403     Right Arrow button used in Picture Buttons demo (similar to above)
  109.  *                420-425     Plus/Minus button used in Picture Buttons demo.  These 4 icons are
  110.  *                                 used in a particularly attractive button.  The top half (+)
  111.  *                                 darkens when you select it, and so does the bottom (-). Two icons
  112.  *                                 (standard and selected position) are used for the top half, and
  113.  *                                 two for the bottom. These icons are part of an icl8 / icl4 / ICN#
  114.  *                                 family.
  115.  *                450-456     Four icons are used to draw a dual-stage button (Power-On /
  116.  *                                 Power-Off) in the Picture Buttons demo; a pair for each stage, one
  117.  *                                 for the standard state and one for the selected (pushed in) state.
  118.  *                                 An additional pair of icons ause used to portray the buttons as
  119.  *                                 disabled; one for Power-On and one for Power-Off.  These icons are
  120.  *                                 part of an icl8 / icl4 / ICN# family.
  121.  *
  122.  *    icl8        - -         Large (32x32 pixel) 8-bit Icons:  These icons are typically used
  123.  *                 only by the Finder to depict an application and its related
  124.  *                 files.  However, your application can also draw these icons with
  125.  *                 Tools Plus.  8-bit icons can have a maximum of 256 colors.
  126.  *                    1,2    These color icons will be used on color monitors as a substitute
  127.  *                 for the system's Note and Caution icons.  They give color
  128.  *                 applications a better look.  Notice that there isn't a Stop icon
  129.  *                 (ID=0).  The equivalent icl4 will be used instead.
  130.  *                    128         Application's Icon (displayed by the Finder.  The BNDL resource
  131.  *                 refers to this icon)
  132.  *                    150         Printer icon used to demonstrate drawing icon families
  133.  *                    151         Modem icon used to demonstrate drawing icon families
  134.  *                400,401     Left Arrow button used in Picture Buttons demo (part of an icl8 /
  135.  *                                 icl4 / ICN# family).  One icon is used for the button's standard
  136.  *                                 position, and another for the selected (pushed in) position.
  137.  *                402,403     Right Arrow button used in Picture Buttons demo (similar to above)
  138.  *                420-425     Plus/Minus button used in Picture Buttons demo.  These 4 icons are
  139.  *                                 used in a particularly attractive button.  The top half (+)
  140.  *                                 darkens when you select it, and so does the bottom (-). Two icons
  141.  *                                 (standard and selected position) are used for the top half, and
  142.  *                                 two for the bottom. These icons are part of an icl8 / icl4 / ICN#
  143.  *                                 family.
  144.  *                450-456     Four icons are used to draw a dual-stage button (Power-On /
  145.  *                                 Power-Off) in the Picture Buttons demo; a pair for each stage, one
  146.  *                                 for the standard state and one for the selected (pushed in) state.
  147.  *                                 An additional pair of icons ause used to portray the buttons as
  148.  *                                 disabled; one for Power-On and one for Power-Off.  These icons are
  149.  *                                 part of an icl8 / icl4 / ICN# family.
  150.  *
  151.  *    ICN#        - -         Large (32x32 pixel) 1-bit Icons with Mask:  These icons are
  152.  *                 typically used only by the Finder to depict an application and
  153.  *                 its related files.  However, your application can also draw these
  154.  *                 icons with Tools Plus.  1-bit icons are black and white (no
  155.  *                 shades of gray).
  156.  *                    128         Application's Icon (displayed by the Finder.  The BNDL resource
  157.  *                 refers to this icon)    
  158.  *                    150         Printer icon used to demonstrate drawing icon families
  159.  *                    151         Modem icon used to demonstrate drawing icon families
  160.  *                400,401     Left Arrow button used in Picture Buttons demo (part of an icl8 /
  161.  *                                 icl4 / ICN# family).  One icon is used for the button's standard
  162.  *                                 position, and another for the selected (pushed in) position.
  163.  *                402,403     Right Arrow button used in Picture Buttons demo (similar to above)
  164.  *                420-425     Plus/Minus button used in Picture Buttons demo.  These 4 icons are
  165.  *                                 used in a particularly attractive button.  The top half (+)
  166.  *                                 darkens when you select it, and so does the bottom (-). Two icons
  167.  *                                 (standard and selected position) are used for the top half, and
  168.  *                                 two for the bottom. These icons are part of an icl8 / icl4 / ICN#
  169.  *                                 family.
  170.  *                450-456     Four icons are used to draw a dual-stage button (Power-On /
  171.  *                                 Power-Off) in the Picture Buttons demo; a pair for each stage, one
  172.  *                                 for the standard state and one for the selected (pushed in) state.
  173.  *                                 An additional pair of icons ause used to portray the buttons as
  174.  *                                 disabled; one for Power-On and one for Power-Off.  These icons are
  175.  *                                 part of an icl8 / icl4 / ICN# family.
  176.  *
  177.  *    ICON        - -         Large (32x32 pixel) 1-bit Icons:  These are standard black &
  178.  *                 white icons.
  179.  *                    0,1,2  These icons will be used as a substitute for the system's Stop,
  180.  *                 Note and Caution icons.  In this case, they are exactly the same
  181.  *                 as System 7's system icons, but they are included in case this
  182.  *                 application runs on System 5 (where the system icons are
  183.  *                 different).  There are color counterparts for these icons (icl4
  184.  *                 and icl8).
  185.  *
  186.  *                304,305     These printer and modem icons appear in "picture Pop-Up Menus"
  187.  *                                 (picture in a Pop-Up Menu without any text) on Macs without Color
  188.  *                                 QuickDraw.  There are 'cicn' equivalents for these items for Macs
  189.  *                                 with Color QuickDraw.
  190.  *
  191.  *    ics4        - -         Small (16x16 pixel) 4-bit Icons:  These icons are typically used
  192.  *                 only by the Finder to depict an application and its related
  193.  *                 files.  4-bit icons can have a maximum of 16 colors.
  194.  *                    128         Application's Icon (displayed by the Finder.  The BNDL resource
  195.  *                 refers to this icon)
  196.  *
  197.  *    ics8        - -         Small (16x16 pixel) 8-bit Icons:  These icons are typically used
  198.  *                 only by the Finder to depict an application and its related
  199.  *                 files.  8-bit icons can have a maximum of 256 colors.
  200.  *                    128         Application's Icon (displayed by the Finder.  The BNDL resource
  201.  *                 refers to this icon)
  202.  *
  203.  *    ics#        - -         Small (16x16 pixel) 1-bit Icons:  These icons are typically used
  204.  *                 only by the Finder to depict an application and its related
  205.  *                 files.  1-bit icons are black & white.
  206.  *                    128         Application's Icon (displayed by the Finder.  The BNDL resource
  207.  *                 refers to this icon)
  208.  *
  209.  *    PICT        - -         Pictures of any dimension, number of colors (including gray scale
  210.  *                 and black & white)
  211.  *                    128         Black & white (1-bit) picture.  It's the black & white equivalent
  212.  *                 of resource 129
  213.  *                    129         Color (8-bit) picture.  It's the color equivalent of resource
  214.  *                 128.
  215.  *                150-173     Complete picture suite needed for a 2-stage button. Each stage
  216.  *                                 (value) can be either or not, and includes different PICTs for
  217.  *                                 screen depths of 8-bits, 4-bits, and B&W. They also include a
  218.  *                                 mask, though this is not necessary when drawing on a white
  219.  *                                 background.
  220.  *
  221.  *  SICN        - -         Small (16x16 pixel) 1-bit Icons:  These icons are "indexed",
  222.  *                                 meaning that you can have multiple icon images in a single 'SICN'
  223.  *                                 resource.
  224.  *                300-303     These color icons (hard disk, floppy, and folder) show up in the
  225.  *                                 Pop-Up Menus demo beside menu item names. They are supplied
  226.  *                                 because Macs without Color QuickDraw need SICNs (they can't use
  227.  *                                 color 'cicn' icons).
  228.  *                408-414  These are all used in the Picture Buttons demo to create 3D icons.
  229.  *                                 Tools Plus converts an SICN icon into a color 3D button.
  230.  *                    458         These are all used in the Picture Buttons demo to create 3D icons.
  231.  *                                 Tools Plus converts an SICN icon into a color 3D button.  Because
  232.  *                                 this SICN resource has several images, each image becomes an
  233.  *                                 available "state" (or usable value).  In this example, the user
  234.  *                                 can step through the stages by clicking on the button.
  235.  *                500-519     These are all used in the Floating Palettes demo to create 3D
  236.  *                                 icons.  Tools Plus converts an SICN icon into a color 3D button.
  237.  *                                 You can create professional looking palettes with different styles
  238.  *                                 of buttons using Tools Plus.
  239.  *
  240.  *    SIZE        -1     Multi-tasking info:  The 'SIZE' resource is needed if your
  241.  *                 application is going to run under MultiFinder (System 5 and 6)
  242.  *                 or System 7.  It tells the Macintosh how your application should
  243.  *                 behave in a multi-tasking environment.  See the User Manual for
  244.  *                 details.
  245.  *
  246.  *    TP 1        128         Owner Resource:  This resource is automatically created when a
  247.  *                 BNDL resource is created. This demo's signature is 'TP 1', and as
  248.  *                 you may recall, each application must have a unique signature
  249.  *                 code (see the User Manual for details).  That signature code is
  250.  *                 used to create an "owner resource" whose resource type is the
  251.  *                 same as the application's signature code.
  252.  *
  253.  *    vers        - -         Application Version:  These resources' information is displayed
  254.  *                 in the Finder's Get Info box.
  255.  *                    1      This information is displayed at the bottom of the Get Info box.
  256.  *                 It includes an application version number and the copyright info.
  257.  *                    2      This information is displayed at the top of the Get Info box.  It
  258.  *                 is a comment that is displayed beneath the application's name
  259.  *                 (ie: "Tools Plus demo").
  260.  *
  261.  *    WDEF        - -         Window Definition:  WDEFs define how a window looks.  If you want
  262.  *                 to open a window that is not one of the six standard Macintosh
  263.  *                 window types, you have to create a window definition.
  264.  *                    2000     Pallet Window:  These windows have a narrow title bar, and are
  265.  *                 typically used as "floating windows" (they are always active, and
  266.  *                 they float above your other windows).  This demo has several
  267.  *                 floating pallets.
  268.  
  269.  
  270.  *    T h e   D e m o s :
  271.  *    This demo application can be used as a framework for a new application, although
  272.  *  you will probably want to improve upon it to cater to your own programming style
  273.  *  and needs.  The demo can be broken down into several sections:
  274.  *
  275.  *        main                    The main program demonstrates a typical application's startup
  276.  *                  and response to events.
  277.  *
  278.  *    PrepareTheDemo    This routine creates the demos menus and opens a couple demo
  279.  *                  windows.
  280.  *
  281.  *        Window 1            This window demonstrates how Tools Plus works with…
  282.  *                                        • List Boxes
  283.  *                                        • Buttons (radio buttons, check boxes and push buttons)
  284.  *                                        • Cursor Zones
  285.  *
  286.  *        Window 2            This window demonstrates how Tools Plus works with…
  287.  *                                        • Editing Fields (typing, Cut, Copy, Paste, Clear, and Undo.
  288.  *                                          Tabbing to next / prev field)
  289.  *                                        • Scroll Bars
  290.  *                                        • "Size box" and the "zoom box" (changing a window's size)
  291.  *
  292.  *        Window 3            This window demonstrates how Tools Plus works with…
  293.  *                                        • drawing icon families
  294.  *                                        • Cursor Zones used to make icons click sensitive
  295.  *
  296.  *        Window 4            This window shows off Tools Plus's cursor animation, and how
  297.  *                                    Tools Plus behaves when a watch cursor is displayed.
  298.  *
  299.  *        Window 5            This window demonstrates how to write code for color drawing
  300.  *                                    that is dependent on the monitor's settings (ie: number of
  301.  *                                    colors, number of shades of gray, or black & white).  It also
  302.  *                                    shows how to write code that is compatible with Macintoshes that
  303.  *                                    have multiple monitors.
  304.  *
  305.  *        Window 6            This demo shows off Tools Plus's Dynamic Alerts.  They are alert
  306.  *                                    boxes that automatically adjust to accommodate the text your
  307.  *                                    application provides them.
  308.  *
  309.  *        Window 7            This window demonstrates Tools Plus's Pop-Up Menus and some of
  310.  *                                    the features you can incorporate into them.
  311.  *
  312.  *        Window 8            This window features Tools Plus's Picture Buttons, which
  313.  *                                    transform icons or pictures into powerful buttons.  Picture
  314.  *                                    Buttons have a list of properties that you can select and combine
  315.  *                                    to create your own custom Picture Buttons.  Picture Button
  316.  *                                    properties control the look and behavior of the button.
  317.  *
  318.  *        Window 9            Window 9 is this application's Tool Bar.  Tools Plus lets you
  319.  *                                    create a Tool Bar as easily as any other Tools Plus window.  You
  320.  *                                    can put any control you want in the Tool Bar, including picture
  321.  *                                    buttons (the most common thing), pop-up menus, and editing fields.
  322.  *                                    Demo Window 8 describes picture buttons in greater detail.
  323.  *
  324.  *        Window 10            Window 10 is this a floating palette.  Tools Plus lets you create
  325.  *                                    a floating palette as easily as any other Tools Plus window.
  326.  *                                    You can put any control you want in the Tool Bar, including
  327.  *                                    picture buttons (the most common thing), pop-up menus, and
  328.  *                                    editing fields.  Demo Window 8 describes picture buttons in
  329.  *                                    greater detail.
  330.  *
  331.  *        Window 11            Window 11 is this also a floating palette (like demo window 10),
  332.  *                                    except this is a horizontal palette with the title bar along the
  333.  *                                    window's left side.
  334.  
  335.  
  336.  
  337.  
  338.  
  339.  *    S o u n d   M a n a g e r :
  340.  *    This demo uses the Sound Manager just for entertainment's sake.  If this demo
  341.  *    runs on a Mac that is running less than System 6, simple beeps will be played
  342.  *    instead of sounds.
  343.  
  344.  
  345.  **********************************************************************************/
  346.  
  347.  
  348.  
  349.                                                                     /* I n c l u d e d   C o d e                                        */
  350. #include "Pascal.h"                                /*    C/Pascal compatibility for Mac toolbox            */
  351. #include "String.h"                                /*    ANSI C string manipulation                                    */
  352. #include "Sound.h"                                /*    Macintosh Sound Manager, used to play a few    */
  353.                                                                     /*      sounds, just for fun.                                            */
  354. #include "ToolsPlus.h"                        /*    Tools Plus header file.  Each program or        */
  355.                                                                     /*      unit that makes reference to a Tools Plus    */
  356.                                                                     /*      #define, struct, or routine needs to use    */
  357.                                                                     /*      this header.                                                            */
  358. #include "PascalStrHandles.c"            /*    Quick 'n' Dirty routines for copying a C        */
  359.                                                                     /*        string to a Pascal "String Handle" and        */
  360.                                                                     /*        vice versa.                                                                */
  361.  
  362.  
  363.  
  364.                                                                     /* D e f i n e s …                                                            */
  365.                                                                     /* These constants, types and variables are            */
  366.                                                                     /*     accessible throughout this program.                */
  367. /*    All these constants will make the demo's code more readable.  You don't    HAVE    */
  368. /*    to use them.  You can use literals, such as 1, 2, 3… if you want to.  It all    */
  369. /*    depends on your writing style and needs.                                                                            */
  370. #define        DemoWindow1                1                /*Window numbers for the demo…                                */
  371. #define        DemoWindow2                2                /*                                                                                        */
  372. #define        DemoWindow3                3                /*                                                                                        */
  373. #define        DemoWindow4                4                /*                                                                                        */
  374. #define        DemoWindow5                5                /*                                                                                        */
  375. #define        DemoWindow6                6                /*                                                                                        */
  376. #define        DemoWindow7                7                /*                                                                                        */
  377. #define        DemoWindow8                8                /*                                                                                        */
  378. #define        ToolBarWindow            9                /*                                                                                        */
  379. #define        VerticalPalette        10            /*                                                                                        */
  380. #define        HorizontalPalette    11            /*                                                                                        */
  381. #define        OkButton                    1                /*Buttons used on Demo Window 1…                            */
  382. #define        CancelButton            2                /*    When writing a real application,                    */
  383. #define        MiniButton1                11            /*    you can give these constants                            */
  384. #define        MiniButton2                12            /*    meaningful names, such as "OK",                        */
  385. #define        MiniButton3                13            /*    "Cancel", "Detail", "Summary" etc.                */
  386. #define        MiniButton4                14            /*                                                                                        */
  387. #define        MiniButton5                15            /*                                                                                        */
  388. #define        CheckBox1                    21            /*                                                                                        */
  389. #define        CheckBox2                    22            /*                                                                                        */
  390. #define        CheckBox3                    23            /*                                                                                        */
  391. #define        RadioButton1            31            /*                                                                                        */
  392. #define        RadioButton2            32            /*                                                                                        */
  393. #define        RadioButton3            33            /*                                                                                        */
  394. #define        MidiHalfMeg                11            /*                                                                                        */
  395. #define        MidiOneMeg                12            /*                                                                                        */
  396. #define        MidiTwoMeg                13            /*                                                                                        */
  397. #define        LeftArrowButton        1                /*Picture Buttons used on Window 8…                        */
  398. #define        RightArrowButton    2                /*    When writing real applications, you can        */
  399. #define        LeftAlignButton        3                /*    use constants, variables, calculations,        */
  400. #define        CenterAlignButton    4                /*    or a number in place of these items.            */
  401. #define        RightAlignButton    5                /*                                                                                        */
  402. #define        JustifyButton            6                /*                                                                                        */
  403. #define        CutButton                    7                /*                                                                                        */
  404. #define        BucketButton            8                /*                                                                                        */
  405. #define        ClipboardButton        9                /*                                                                                        */
  406. #define        PlusButton                10            /*                                                                                        */
  407. #define        MinusButton                11            /*                                                                                        */
  408. #define        PrinterButton            12            /*                                                                                        */
  409. #define        ModemButton                13            /*                                                                                        */
  410. #define        SteppingButton        14            /*                                                                                        */
  411. #define        ScrollingButton        15            /*                                                                                        */
  412. #define        GlobeButton                16            /*                                                                                        */
  413. #define        RewindButton            17            /*                                                                                        */
  414. #define        StopButton                18            /*                                                                                        */
  415. #define        FastFwdButton            19            /*                                                                                        */
  416. #define        PauseButton                20            /*                                                                                        */
  417. #define        RecordButton            21            /*                                                                                        */
  418. #define        PlayButton                22            /*                                                                                        */
  419. #define        PowerButton                23            /*                                                                                        */
  420. #define        FlipButton                24            /*                                                                                        */
  421. #define        DoneButton                25            /*                                                                                        */
  422. #define        VPaletteMinButton 1                /*First and last picture button used on the        */
  423. #define        VPaletteMaxButton 20            /*    vertical floating palette demo.                        */
  424. #define        HPaletteMinButton 1                /*First and last picture button used on the        */
  425. #define        HPaletteMaxButton 22            /*    horizontal floating palette demo.                    */
  426. #define        LeftArrowIcon            400            /*Icons and pictures used to make Picture            */
  427. #define        RightArrowIcon        404            /*    Buttons on Window 8…                                            */
  428. #define        LeftAlignIcon            408            /*                                                                                        */
  429. #define        CenterAlignIcon        409            /*                                                                                        */
  430. #define        RightAlignIcon        410            /*                                                                                        */
  431. #define        JustifyIcon                411            /*                                                                                        */
  432. #define        CutIcon                        412            /*                                                                                        */
  433. #define        BucketIcon                413            /*                                                                                        */
  434. #define        ClipboardIcon            414            /*                                                                                        */
  435. #define        PlusIcon                    420            /*                                                                                        */
  436. #define        MinusIcon                    424            /*                                                                                        */
  437. #define        ScrollingIcon            458            /*                                                                                        */
  438. #define        GlobeIcon                    460            /*                                                                                        */
  439. #define        RewindIcon                430            /*                                                                                        */
  440. #define        StopTapeIcon            432            /*                                                                                        */
  441. #define        FastFwdIcon                434            /*                                                                                        */
  442. #define        PauseIcon                    436            /*                                                                                        */
  443. #define        RecordIcon                438            /*                                                                                        */
  444. #define        PlayIcon                    440            /*                                                                                        */
  445. #define        PowerIcon                    450            /*                                                                                        */
  446. #define        FlipSwitchPICT        150            /*                                                                                        */
  447. #define        DoneIcon                    464            /*                                                                                        */
  448. #define        FirstVPaletteIcon 500            /*First icon number on the vert. and horiz.        */
  449. #define        FirstHPaletteIcon 520            /*    palettes. Other icons nums are calculated.*/
  450. #define        LeftList                    1                /*List Boxes used on Demo Window 1…                        */
  451. #define        RightList                    2                /*                                                                                        */
  452. #define        RightBar                    1                /*Scroll Bars used on Demo Window 2…                    */
  453. #define        BottomBar                    2                /*                                                                                        */
  454. #define        ApplMenu                    0                /*Menus and Menu Items…                                                */
  455. #define        AboutItem                    1                /*                                                                                        */
  456. #define        FileMenu                    1                /*                                                                                        */
  457. #define        CloseItem                    3                /*                                                                                        */
  458. #define        QuitItem                    5                /*                                                                                        */
  459. #define        EditMenu                    2                /*                                                                                        */
  460. #define        DemosMenu                    3                /*                                                                                        */
  461. #define        ToolBarItem                10            /*Item number for Tool Bar on the Demos menu    */
  462. #define        PaletteDemoMenu     16            /*Hierarchic menus use numbers 16-200                    */
  463. #define        popMenu1                    1                /*Pop-Up Menu numbers                                                    */
  464. #define        popMenu2                    2                /*                                                                                        */
  465. #define        popMenu3                    3                /*                                                                                        */
  466. #define        popMenu4                    4                /*                                                                                        */
  467. #define        popMenu5                    5                /*                                                                                        */
  468. #define        ButtonSpeedMenu        6                /*                                                                                        */
  469.  
  470.  
  471.  
  472. #define        PrinterIcon                150            /*Printer and Modem icons…                                        */
  473. #define        ModemIcon                    151            /*                                                                                        */
  474. #define        BlackAndWhitePICT    128            /*Color and Black & White pictures…                        */
  475. #define        ColorPICT                    129            /*                                                                                        */
  476. #define        WatersEdgeLogo        128            /*Logo for Water's Edge Software (icons)            */
  477.  
  478.  
  479.  
  480.                                                                                 /* T y p e   D e f i n i t i o n s …            */
  481. typedef        unsigned char            Str30[31];    /*A 30-character string                                        */
  482.  
  483.  
  484.  
  485.                                                                                 /* G l o b a l   R o u t i n e s …                */
  486. void PrepareTheDemo (void);                            /* Prepare (initialize) the demo appl.        */
  487. void CloseTheWindow (short Window);            /* Close a window                                                    */
  488. void ActionInWindow1 (void);                        /* Respond to user's action in window 1        */
  489. void ActionInWindow2 (void);                        /* Respond to user's action in window 2        */
  490. void ActionInWindow3 (void);                        /* Respond to user's action in window 3        */
  491. void ActionInWindow4 (void);                        /* Respond to user's action in window 4        */
  492. void ActionInWindow5 (void);                        /* Respond to user's action in window 5        */
  493. void ActionInWindow6 (void);                        /* Respond to user's action in window 6        */
  494. void ActionInWindow7 (void);                        /* Respond to user's action in window 7        */
  495. void ActionInWindow8 (void);                        /* Respond to user's action in window 8        */
  496. void ActionInWindow8_DrawToolBarValue (void);    /* Supporting routines for drawing    */
  497. void ActionInWindow8_DrawGlobeValue (void);        /*        objects in window 8.                    */
  498. void ActionInWindow9 (void);                        /* Respond to user's action in window 9        */
  499. void ActionInWindow10 (void);                        /* Respond to user's action in window 10    */
  500. void ActionInWindow11 (void);                        /* Respond to user's action in window 11    */
  501.                                                                                 /* Draw text in a specified rectangle…        */
  502. void TextInBox (char Str[], short left, short top, short right, short bottom, short Justification, Boolean withBox);
  503. void stoa (short n, char s[]);                    /* Convert a short to a C string                    */
  504.                                                                                 /* Draw a group box with a title…                    */
  505. void GroupBox (Str255 Str, short left, short top, short right, short bottom);    /*    */
  506. void DrawWindow1Contents (void);                /* Draw the contents of window 1                    */
  507. void DrawWindow2Contents (void);                /* Draw the contents of window 2                    */
  508. void DrawWindow3Contents (void);                /* Draw the contents of window 3                    */
  509. void DrawWindow4Contents (void);                /* Draw the contents of window 4                    */
  510. void DrawWindow5Contents (void);                /* Draw the contents of window 5                    */
  511. void DrawWindow6Contents (void);                /* Draw the contents of window 6                    */
  512. void DrawWindow7Contents (void);                /* Draw the contents of window 7                    */
  513. void DrawWindow8Contents (void);                /* Draw the contents of window 8                    */
  514. void DrawWindow9Contents (void);                /* Draw the contents of window 9                    */
  515. void DrawWindow10Contents (void);                /* Draw the contents of window 10                    */
  516. void DrawWindow11Contents (void);                /* Draw the contents of window 11                    */
  517. void OpenDemoWindow1 (void);                        /* Open Demo Window 1                                            */
  518. void OpenDemoWindow2 (void);                        /* Open Demo Window 2                                            */
  519. void OpenDemoWindow3 (void);                        /* Open Demo Window 3                                            */
  520. void OpenDemoWindow4 (void);                        /* Open Demo Window 4                                            */
  521. void OpenDemoWindow5 (void);                        /* Open Demo Window 5                                            */
  522. void OpenDemoWindow6 (void);                        /* Open Demo Window 6                                            */
  523. void OpenDemoWindow7 (void);                        /* Open Demo Window 7                                            */
  524. void OpenDemoWindow8 (void);                        /* Open Demo Window 8                                            */
  525. void OpenDemoWindow9 (void);                        /* Open Demo Window 9                                            */
  526. void OpenDemoWindow10 (void);                        /* Open Demo Window 10                                        */
  527. void OpenDemoWindow11 (void);                        /* Open Demo Window 11                                        */
  528. void RefreshWindow (void);                            /* Respond to a doRefresh event                        */
  529. void ChangeWindow (void);                                /* Respond to a doChgWindow event                    */
  530. void MenuSelection (void);                            /* Respond to a doMenu event                            */
  531.  
  532.  
  533.  
  534.  
  535.  
  536.                                                                                 /* G l o b a l   V a r i a b l e s …            */
  537. TPPollRecord    Poll;                                            /*Polling record to retrieve event info        */
  538. Handle                hField1;                                    /*Handle to 1st editing field's 30-char        */
  539.                                                                                 /*    string.                                                                */
  540. Handle                hField2, hField3;                    /*Handles to 2nd and 3rd editing fields'    */
  541.                                                                                 /*    255-char string.                                            */
  542. short                    MidiPort;                                    /*Serial port selected for MIDI                        */
  543.                                                                                 /*    interface (Demo 3).                                        */
  544. RGBColor            ToolBarGray;                            /*Color of toolbar                                                */
  545. short                    ToolBarValue;                            /*Value displayed in a window's tool bar    */
  546.                                                                                 /*    (Demo 8)                                                            */
  547. short                    MidiSpeed;                                /*MIDI interface speed (Demo 3)                        */
  548. Boolean                ExitTheDemo;                            /*Should the demo terminate?                            */
  549.  
  550.  
  551.  
  552.  
  553.  
  554. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  555.  * M a i n   P r o g r a m :
  556.  *    The main program demonstrates the detection of, and response to events.
  557.  *    Tools Plus events are more usable than those obtained from The Event Manager.
  558.  *
  559.  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  560.  void main(void)                                                                
  561.     {
  562.     InitGraf(&thePort);                                                /*Standard Mac ToolBox initialization    */
  563.     InitFonts();                                                            /*    required by all applications.            */
  564.     InitWindows();                                                        /*                                                                        */
  565.     InitMenus();                                                            /*                                                                        */
  566.     TEInit();                                                                    /*                                                                        */
  567.     InitDialogs(0L);                                                    /*                                                                        */
  568.     MaxApplZone();                                                        /*Expand application zone to its limit*/
  569.  
  570.     if (!InitToolsPlus(5, 11, UseColor))            /*Initialize Tools Plus with "5"            */
  571.         ExitToShell();                                                    /*    handle blocks, and a maximum of        */
  572.                                                                                         /*    "11" open windows.  Use Color            */
  573.                                                                                         /*    QuickDraw if it’s available.  If    */
  574.                                                                                         /*    initialization fails, return to        */
  575.                                                                                         /*    the Finder.                                                */
  576.     PrepareTheDemo();                                                    /*Prepare the demo by creating the        */
  577.                                                                                         /*    menus and opening a sample window.*/
  578.  
  579.     ExitTheDemo = false;                                            /*The demo is not over yet                        */
  580.     while (!ExitTheDemo)                                            /*Keep polling for an event until the    */
  581.         {                                                                                /*    Quit item is selected in the File    */
  582.                                                                                         /*    menu…                                                            */
  583.         if (PollSystem(&Poll))                                     /*If an event has been detected…            */
  584.             {                                                                            /*                                                                        */
  585.            switch (Poll.What)                                        /*Determine what kind of event has        */
  586.                {                                                                        /*    occurred…                                                    */
  587.                 case doMenu:                                                 /*User selected a menu item…                    */
  588.                     MenuSelection();                                    /*    execute that menu item.                        */
  589.                     break;                                                        /*                                                                        */
  590.                 case doChgWindow:                                     /*User clicked on an inactive window…    */
  591.                     ChangeWindow();                                     /*    activate the window the user            */
  592.                     break;                                                        /*    clicked.                                                    */
  593.                 case doRefresh:                                         /*A window needs to be refreshed…            */
  594.                     RefreshWindow();                                    /*    redraw the specified window.            */
  595.                     break;                                                        /*                                                                        */
  596.                 case doGoAway:                                             /*User clicked a window's "close box"…*/
  597.                     CloseTheWindow(Poll.Window);            /*    close the affected window.                */
  598.                     break;                                                        /*                                                                        */
  599.                 case doButton:         case doPictButton:/*The user has clicked a button, typed*/
  600.                 case doKeyDown:     case doAutoKey:        /*    a key, clicked in an inactive            */
  601.                 case doClickField:case doScrollBar:    /*    field, used a scroll bar, clicked    */
  602.                 case doListBox:     case doPopUpMenu:    /*    a line in a list box, used a Pop-    */
  603.                 case doClick:                                                /*    Up Menu, or clicked in the window    */
  604.                                                                                         /*    (not on an object)…                                */
  605.                     if (Poll.Window != none)                    /*If the event is applied to an open    */
  606.                         {                                                                /*    window (ignore events if no window*/
  607.                                                                                         /*    is open)…                                                    */
  608.                    CurrentWindow(Poll.Window);            /*Make the affected window current.        */
  609.                                                                                    /*    It will be the target of actions    */
  610.                                                                                    /*    that are made in response to the    */
  611.                                                                                    /*    user's activity in the affected        */
  612.                                                                                    /*    window.                                                        */
  613.                         switch (Poll.Window)                        /*Determine which window is affected    */
  614.                             {                                                            /*    and call the appropriate routine    */
  615.                             case 1:                                             /*    to respond to the user's activity    */
  616.                            ActionInWindow1();                    /*     (ie: call a window-handler                */
  617.                            break;                                            /*    routine).                                                    */
  618.                             case 2:                                             /*                                                                        */
  619.                            ActionInWindow2();                    /*                                                                        */
  620.                            break;                                            /*                                                                        */
  621.                             case 3:                                             /*                                                                        */
  622.                            ActionInWindow3();                    /*                                                                        */
  623.                            break;                                            /*                                                                        */
  624.                             case 4:                                             /*                                                                        */
  625.                            ActionInWindow4();                    /*                                                                        */
  626.                            break;                                            /*                                                                        */
  627.                             case 5:                                             /*                                                                        */
  628.                            ActionInWindow5();                    /*                                                                        */
  629.                            break;                                            /*                                                                        */
  630.                             case 6:                                             /*                                                                        */
  631.                            ActionInWindow6();                    /*                                                                        */
  632.                            break;                                            /*                                                                        */
  633.                             case 7:                                             /*                                                                        */
  634.                            ActionInWindow7();                    /*                                                                        */
  635.                            break;                                            /*                                                                        */
  636.                             case 8:                                             /*                                                                        */
  637.                            ActionInWindow8();                    /*                                                                        */
  638.                            break;                                            /*                                                                        */
  639.                             case 9:                                             /*                                                                        */
  640.                            ActionInWindow9();                    /*                                                                        */
  641.                            break;                                            /*                                                                        */
  642.                             case 10:                                             /*                                                                        */
  643.                            ActionInWindow10();                    /*                                                                        */
  644.                            break;                                            /*                                                                        */
  645.                             case 11:                                             /*                                                                        */
  646.                            ActionInWindow11();                    /*                                                                        */
  647.                            break;                                            /*                                                                        */
  648.                             }                                                            /*                                                                        */
  649.                         }                                                                /*                                                                        */
  650.                    break;                                                    /*                                                                        */
  651.                    
  652.             default:                                                        /*All other events are ignored by            */
  653.                      break;                                                        /*    this demo.                                                */
  654.               }                                                                        /*                                                                        */
  655.             }                                                                            /*                                                                        */
  656.         else                                                                        /*If this demo was to perform on-going*/
  657.            {                                                                            /*    operations, perhaps even when            */
  658.                                                                                        /*    suspended, that code would go            */
  659.            }                                                                            /*    here.                                                            */
  660.         }                                                                                /*                                                                        */
  661.  
  662.      CursorShape(watchCursor);                                    /*Change the cursor to a wrist watch    */
  663.                                                                                          /*    as the demo quits to the Finder.    */
  664.                                                                                          /*    Visually, it looks more                        */
  665.                                                                                          /*    professional to "look busy" while    */
  666.      }                                                                                    /*    the application quits.                        */
  667.  
  668.  
  669.  
  670.  
  671. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  672.  * P r e p a r a t i o n s :
  673.  *    This routine does all the "set up" work for the demo, such as creating the
  674.  *    menus and introducing the demo. In a full-featured application, you would
  675.  *    probably open documents that were double-clicked from the Finder.
  676.  *
  677.  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  678. void PrepareTheDemo (void)
  679.     {
  680.     #define            QuitAlert                         11700        /*Button definition for a "Quit"            */
  681.                                                                                         /*    Dynamic Alert.                                        */
  682.     #define            SilentContinueAlert    -11500        /*Button definition for a "Continue"    */
  683.                                                                                         /*    dynamic alert that doesn't beep        */
  684.                                                                                         /*    the user.                                                    */
  685.  
  686.  
  687.   SetNullTime(1, maxNullTime);                            /*Be a good neighbor to other appls by*/
  688.                                                                                         /*    using fewer CPU cycles.                        */
  689.     CursorShape(watchCursor);                                    /*Change the cursor to a wrist watch    */
  690.   MidiPort = ModemIcon;                                            /*By default, select the modem port        */
  691.   MidiSpeed = MidiOneMeg;                                        /*    for a MIDI interface running at        */
  692.                                                                                       /*    1 MHz. (demo window 3)                        */
  693.   ToolBarGray.red = 52428;                                    /*Define the toolbar color as a medium*/
  694.   ToolBarGray.green = 52428;                                /*    dark gray.                                                */
  695.   ToolBarGray.blue = 52428;                                    /*                                                                        */
  696.  
  697.                                                                                         /* M e n u s :    -    -    -    -    -    -    -    -    -    -    -    */
  698.   AppleMenu("\pAbout The Demo…");                        /*Create the Apple menu with an                */
  699.                                                                                       /*    "About…" item.  You can now work    */
  700.                                                                                       /*    with anything in the Apple menu        */
  701.                                                                                       /*    without having to write code for    */
  702.                                                                                       /*    it!                                                                */
  703.   Menu(FileMenu, 0, enabled, "\pFile");            /*File menu:create menu name (menu 1)    */
  704.   Menu(FileMenu, 1, disabled, "\pNew/N");        /*            create "New" item (1st item)    */
  705.   Menu(FileMenu, 2, disabled, "\pOpen/O");    /*            create "Open" item (2nd item)    */
  706.   Menu(FileMenu, 3, disabled, "\pClose/W");    /*            create "Close" item (3rd item)*/
  707.   Menu(FileMenu, 4, disabled,mDividingLine);/*            4th item is a dividing line        */
  708.   Menu(FileMenu, 5, enabled, "\pQuit/Q");        /*            create "Quit" item (5th item)    */
  709.   Menu(EditMenu, 0, enabled, "\pEdit");            /*Edit menu: create menu name (menu 2)*/
  710.   Menu(EditMenu, 1, disabled, "\pUndo/Z");    /*            The Undo, Cut, Copy, Paste,        */
  711.   Menu(EditMenu, 2, disabled,mDividingLine);/*            and Clear items are all                */
  712.   Menu(EditMenu, 3, disabled, "\pCut/X");        /*            disabled.  They are                        */
  713.   Menu(EditMenu, 4, disabled, "\pCopy/C");    /*            automatically enabled as            */
  714.   Menu(EditMenu, 5, disabled, "\pPaste/V");    /*            required when working with        */
  715.   Menu(EditMenu, 6, disabled, "\pClear");        /*            editing fields.  Your                    */
  716.   Menu(EditMenu, 7, disabled,mDividingLine);/*            application can also manually    */
  717.   Menu(EditMenu, 8, disabled, "\pShow Clipboard…");    /*    enable/disable these items*/
  718.                                                                                       /*            when working with other                */
  719.                                                                                       /*            objects such as graphics.            */
  720.                                                                                         /*                The Edit menu is needed for    */
  721.                                                                                         /*            desk accessories and editing    */
  722.                                                                                         /*            fields.  More items can be        */
  723.                                                                                         /*            added to the Edit menu, and        */
  724.                                                                                         /*            your application has full            */
  725.                                                                                         /*            control of these items.                */
  726.   Menu(DemosMenu, 0, enabled, "\pDemos");        /*Demos:    The "Demos" menu lets you        */
  727.   Menu(DemosMenu, 1, enabled, "\pLists, Buttons and Cursor Zones/1");    /*    open any*/
  728.   Menu(DemosMenu, 2, enabled, "\pFields, Zooming and Scroll Bars/2");    /*    of the    */
  729.   Menu(DemosMenu, 3, enabled, "\pIcons and Cursor Zones/3");                    /*    windows    */
  730.   Menu(DemosMenu, 4, enabled, "\pCursor Animation/4");                                /*    that        */
  731.   Menu(DemosMenu, 5, enabled, "\pColor Drawing and Multiple Monitors/5");    /*    were*/
  732.   Menu(DemosMenu, 6, enabled, "\pDynamic Alert Boxes/6");                            /*    created    */
  733.     Menu(DemosMenu, 7, enabled, "\pPop-Up Menus/7");        /*to demonstrate a few of        */
  734.     Menu(DemosMenu, 8, enabled, "\pPicture Buttons/8");    /*    Tools Plus's features.    */
  735.   Menu(DemosMenu, 9, disabled, mDividingLine);                /*                                                    */
  736.   Menu(DemosMenu, 10, enabled, "\pShow Tool Bar");        /*                                                    */
  737.                                                                                       /*This item will become an hierarchic    */
  738.                                                                                       /*    menu…                                                            */
  739.   Menu(DemosMenu, 11, enabled, "\pFloating Palettes (Windoids)");        /*                        */
  740.                                                                                       /*Create an hierarchic menu by                */
  741.                                                                                       /*    defining the menu items…                    */
  742.   Menu(PaletteDemoMenu, 1, enabled, "\pVertical Orientation");        /*                            */
  743.   Menu(PaletteDemoMenu, 2, enabled, "\pHorizontal Orientation");    /*                            */
  744.   AttachMenu(DemosMenu, 11, PaletteDemoMenu);/*Attach the hierarchic "palettes"        */
  745.                                                                                       /*    menu to the 11th item in the            */
  746.                                                                                       /*    "Demos" pull-down menu.                        */
  747.   UpdateMenuBar();                                                    /*Draw the menu bar with all its menu    */
  748.                                                                                       /*    names.                                                        */
  749.  
  750.                                                                                         /* E d i t i n g   F i e l d s :    -    -    */
  751.   hField1 = (Handle)NewStrHandle(30);                /*Allocate memory for the editing            */
  752.   hField2 = (Handle)NewStrHandle(255);            /*    fields' strings.  Tools Plus            */
  753.   hField3 = (Handle)NewStrHandle(255);            /*    fields reference their related        */
  754.                                                                                       /*    string by this handle.                        */
  755.  
  756.                                                                                         /*Display an alert that tells the user*/
  757.                                                                                         /*    how to use the demo…                            */
  758.     AlertBox(WatersEdgeLogo, "\pWelcome to the Tools Plus demo.\r\rUse the “Demos” menu to explore each of the demos prepared for you.  Feel free to play around with the various objects.\r\rClick “Continue” to start the first demo.", SilentContinueAlert);
  759.   OpenDemoWindow1();                                                /*Open the first demo window                    */
  760.   ResetCursor();                                                        /*Get rid of the wrist watch cursor        */
  761.                                                                                       /*    by resetting it to its proper            */
  762.                                                                                       /*    shape (Tools Plus figures out its    */
  763.                                                                                       /*    proper shape depending on where        */
  764.   }                                                                                    /*    it is on the screen).                            */
  765.  
  766.  
  767.  
  768.  
  769.  
  770.  
  771.  
  772.  
  773.  
  774.  
  775. /***********************************************************************************
  776.  ***********************************************************************************
  777.  *  A c t i o n   i n   a   d e m o   W i n d o w :
  778.  *    The following routines respond to actions made by the user in a demo window.
  779.  *    They are invoked by the main event loop whenever the user does any of the
  780.  *    following things:
  781.  *        • Click a button                                            (doButton event)
  782.  *        • Type a key                                                    (doKeyDown or doAutoKey event,
  783.  *                                                                                     excluding those in editing fields)
  784.  *        • Click in an inactive editing field    (doClickField event)
  785.  *        • Use a scroll bar                                        (doScrollBar event, excluding those
  786.  *                                                                                     in List Boxes)    
  787.  *        • Click a line in a List Box                    (doListBox)
  788.  *        • Use a Pop-Up Menu                                        (doPopUpMenu)
  789.  *        • Click in the window                                    (doClick, excluding clicking on other
  790.  *                                                                                     objects listed above)
  791.  */
  792.  
  793.  
  794.  
  795.  
  796. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  797.  * C l o s e   A   W i n d o w :
  798.  *    This routine is called in response to a "doGoAway" event, the File menu's Close
  799.  *    command, and any from some demos that end when you click the Cancel or OK
  800.  *    button.  Note that a doGoAway event is not generated when a desk accessory's
  801.  *    "close" box is clicked.
  802.  *        A doGoAway event indicates that the user clicked the active window's "close
  803.  *    box".  In a full featured application, you may want to validate the active
  804.  *    editing field and perform any other verifications before closing the window.
  805.  *
  806.  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  807. void CloseTheWindow (short Window)                    /*Window number being closed                    */
  808.     {
  809.     WindowClose(Window);                                            /*Close the specified window                    */
  810.     if (FirstWindowNumber() == none)                    /*If this application does not have        */
  811.                                                                                         /*    any open windows…                                    */
  812.         EnableMenu(FileMenu, CloseItem, disabled);    /*Disable the File menu's Close        */
  813.                                                                                                 /*    command, because all the            */
  814.     }                                                                                            /*    windows are closed.                        */
  815.  
  816.  
  817.  
  818.  
  819. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  820.  * A c t i o n   i n   D e m o   W i n d o w   1 :
  821.  *    This routine responds to actions made by the user in demo window 1.  The actions
  822.  *    include:
  823.  *        • Clicking or double-clicking a line in a List Box
  824.  *        • Clicking a check box
  825.  *        • Clicking or double clicking a radio button
  826.  *        • Clicking a push-button
  827.  *    Notice that if you type Enter or Return, Tools Plus automatically selects the
  828.  *    default push button (OK).
  829.  *
  830.  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  831. void ActionInWindow1 (void)
  832.     {
  833.     Boolean            CheckedBox;                                        /*Was the clicked check box originally*/
  834.                                                                                         /*    selected?                                                    */
  835.   short                ButtonNum;                                        /*Button counter for stepping through */
  836.                                                                                       /*    as set of buttons.                                */
  837.   short                NumberOfSounds;                                /*Number of sounds in the System file    */
  838.   short                SoundIndex;                                        /*Relative sound number going to be        */
  839.                                                                                       /*    played.                                                        */
  840.   Handle            hSound;                                                /*Handle to a sound resource                    */
  841.   short                OSerr;                                                /*Macintosh operating system error        */
  842.  
  843.  
  844.   switch (Poll.What)                                                /*Determine what the user did (what        */
  845.       {                                                                                /*    event)…                                                        */
  846.  
  847.         case doButton:                              /* B u t t o n   W a s   S e l e c t e d :    - - -    */
  848.                                                                 /*This section demonstrates typical interaction        */
  849.                                                                 /*    with check boxes, radio button groups and            */
  850.                                                                 /*    push buttons.  Look at the radio-button group    */
  851.                                                               /*    for "double-clicking" ability.                                */
  852.  
  853.         switch (Poll.Button.Num) {                        /*Determine which button was selected…*/
  854.             case MiniButton1:case MiniButton2:    /* M i n i - B u t t o n s :    -        -        */
  855.             case MiniButton3:case MiniButton4:    /*The mini buttons simply play one of    */
  856.             case MiniButton5:                                        /*    the sounds available in the System*/
  857.                                                                                   /*    file.                                                            */
  858.                     NumberOfSounds = CountResources('snd ');    /*Determine the number of            */
  859.                                                                                                         /*    sounds available.                    */                                                        
  860.                     if ((NumberOfSounds == none) || (SystemVersion() < 6.0))    /*If there are*/
  861.                         Beep();                                                    /*    no sounds available, or if the        */
  862.                                                                                         /*    System version does not support        */
  863.                                                                                         /*    the Sound Manager (older than            */
  864.                                                                                         /*    System 6), just beep the user.        */
  865.                     else                                                            /*If there are sounds available in the*/
  866.                         {                                                                /*    System, calculate a "sound index"    */
  867.                                                                                         /*    number such that button 1 is the    */
  868.                                                                                         /*    first sound, button 2 is the            */
  869.                                                                                         /*    second, etc…                                            */
  870.                    SoundIndex = max(1, (Poll.Button.Num - (MiniButton1 - 1)) % NumberOfSounds);
  871.                   hSound = GetIndResource('snd ', SoundIndex);/*Load the sound resource    */
  872.                                                                                                           /*    from the System file    */
  873.                      OSerr = SndPlay(nil, hSound, false);/*Play the sound resource (ignore    */
  874.                                                                                            /*    the error)                                        */
  875.                   ReleaseResource(hSound);                /*Release the resource to conserve        */
  876.                                                                                    /*    memory.                                                        */
  877.                   }                                                                /*                                                                        */
  878.               break;                                                        /*                                                                        */
  879.           
  880.           
  881.                 case CheckBox1:case CheckBox2:            /* C h e c k   B o x e s :    -        -        -    */
  882.                 case CheckBox3:                                            /*When a check box is clicked, it            */
  883.                                                                                         /*    reverses its current state (If on,*/
  884.                                                                                         /*    turn off.  If off, turn on). In        */
  885.                                                                                         /*    this example, the third check box    */
  886.                                                                                         /*    can only be selected if the second*/
  887.                                                                                         /*    one is selected.                                    */
  888.                     CheckedBox = ButtonIsSelected(Poll.Button.Num);    /*Determine if check box*/
  889.                                                                                         /*    was originally selected.                    */
  890.                CheckedBox = !CheckedBox;                    /*Reverse the check box's selection        */
  891.                SelectButton(Poll.Button.Num, CheckedBox);    /*    (if on, turn    off.  If    */
  892.                                                                                                        /*    off, turn on.)                    */
  893.                     if (Poll.Button.Num == CheckBox2)    /*If the second check box was clicked…*/
  894.                         {                                                                /*    enable/disable button CheckBox3.    */
  895.                    if (CheckedBox)                                    /*    This shows how easy it is to set    */
  896.                        EnableButton(CheckBox3, enabled);/*    up an "and" condition with two    */
  897.                                                                                    /*    or more check boxes.                            */
  898.                    else                                                        /*        Check box 3 is deselected and        */
  899.                        {                                                            /*    disabled when check box 2 is not    */
  900.                        EnableButton(CheckBox3, disabled);        /*    selected.  When check box    */
  901.                        SelectButton(CheckBox3, notSelected);    /*    2 is selected, then check    */
  902.                            }                                                                            /*    box 3 is enabled.                    */
  903.                         }                                                                                /*                                                        */
  904.                     break;                                                                        /*                                                        */
  905.                     
  906.                     
  907.                 case RadioButton1:case RadioButton2:/* R a d i o   B u t t o n s :    -        -    */
  908.                 case RadioButton3:                                    /*Radio buttons are logically                    */
  909.                                                                                         /*    organized into groups, and only        */
  910.                                                                                         /*    one radio button can be on at a        */
  911.                                                                                         /*    time.  Your application can                */
  912.                                                                                         /*    optionally do something else if a    */
  913.                                                                                         /*    radio button is double- clicked.    */
  914.                                                                                         /*    In this case, it is the equivalent*/
  915.                                                                                         /*    of selecting the radio button and    */
  916.                                                                                         /*    clicking OK.                                            */
  917.                     for (ButtonNum = RadioButton1; ButtonNum <= RadioButton3; ButtonNum++)
  918.                                                                                         /*Cycle through each button in the        */
  919.                                                                                         /*    group…                                                        */
  920.                    SelectButton(ButtonNum, ButtonNum == Poll.Button.Num);    /*Select the    */
  921.                                                                                    /*    clicked one, deselect the others.    */
  922.                if (Poll.Button.DoubleClick)            /*If a radio button was double-clicked*/
  923.                   {                                                                /*    it means "select this button and    */
  924.                   FlashButton(OkButton);                    /*    OK".  Flash the OK button to            */
  925.                   CloseTheWindow(DemoWindow1);        /*    indicate it's being selected.            */
  926.                    }                                                                /*    End this demo by closing its            */
  927.               break;                                                        /*    window.                                                        */
  928.  
  929.  
  930.                 case CancelButton:case OkButton:        /* P u s h   B u t t o n s :    -        -        */
  931.                 CloseTheWindow(DemoWindow1);            /*If the user clicked Cancel or OK…        */
  932.                                                                                   /*    end this demo by closing its            */
  933.               break;                                                        /*    window.                                                        */
  934.  
  935.             }                                                                            /*                                                                        */
  936.             break;                                                                /* (end of doButton responses)                */
  937.  
  938.  
  939.         case doListBox:                          /* L i s t   B o x e s :    - - - - - - - - - - - -    */
  940.                                                                 /*Your application may want to respond to a user    */
  941.                                                                 /*    selecting a line in a List Box.  This demo        */
  942.                                                                 /*    just responds to double-clicks by being the        */
  943.                                                                 /*    equivalent of selecting the line and clicking    */
  944.                                                                 /*    OK.                                                                                        */
  945.         if (Poll.ListBox.DoubleClick)                    /*If a list box was double-clicked…        */
  946.              {                                                                        /*    it means "select this line and        */
  947.              FlashButton(OkButton);                            /*    OK".  Flash the OK button to            */
  948.                                                                                      /*    indicate it's being selected. End    */
  949.           CloseTheWindow(DemoWindow1);                /*    this demo by closing its window.    */
  950.              }                                                                        /*                                                                        */
  951.          break;                                                                /*                                                                        */
  952.  
  953.         default:;                                                                /*All other events are ignored in this*/
  954.       }                                                                                /*    demo.                                                            */
  955.   }                                                                                    /*                                                                        */
  956.  
  957.  
  958.  
  959.  
  960. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  961.  * A c t i o n   i n   D e m o   W i n d o w   2 :
  962.  *    This routine responds to actions made by the user in demo window 2.  The
  963.  *    actions include:
  964.  *        • Clicking or double-clicking in an inactive editing field
  965.  *        • Using Scroll Bars
  966.  *        • Tabbing to the next (or previous) field
  967.  *
  968.  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  969. void ActionInWindow2 (void)
  970.     {
  971.   short                Field;                                                /*Field number                                                */
  972.  
  973.  
  974.   switch (Poll.What)                                                /*Determine what the user did (what        */
  975.       {                                                                                /*    event)…                                                        */
  976.  
  977.          case doClickField:                    /* I n a c t i v e   F i e l d   C l i c k e d :    */
  978.                                                                 /*In a full-featured application, you would likely*/
  979.                                                                 /*    validate a field for errors before proceeding    */
  980.                                                                 /*    to the one clicked by the user.  In this demo,*/
  981.                                                                 /*    no validation is done.                                                */
  982.                                                             /*                                                */
  983.             SaveFieldString();                                        /*Save the field's edited text as the    */
  984.                                                                                         /*    field's string.                                        */
  985.             ClickInField();                                                /*Process the event to activate the        */
  986.                                                                                         /*    clicked field and to set the            */
  987.                                                                                         /*    insertion point or selection range*/
  988.             break;                                                                /*    as per the click.                                    */
  989.  
  990.  
  991.         case doScrollBar:                        /* S c r o l l   B a r   W a s   U s e d :    -    -    -    */
  992.                                                                 /*Tools Plus tells your application when a scroll    */
  993.                                                                 /*    bar is used by either clicking in the up            */
  994.                                                                 /*    arrow, down arrow, "page up" region, "page        */
  995.                                                                 /*    down" region, or by moving the thumb.  Your        */
  996.                                                                 /*    application would then respond by doing                */
  997.                                                                 /*    something.  This demo doesn't actually scroll    */
  998.                                                                 /*    anything.                                                                            */
  999.                                                                 /*        Note: When setting a Scroll Bar's value,        */
  1000.                                                                 /*    the minimum / maximum limit are automatically    */
  1001.                                                                 /*    adjusted (if necessary).  Here we use the            */
  1002.                                                                 /*    limits to prevent the current value from            */
  1003.                                                                 /*    being exceeded.                                                                */
  1004.         switch (Poll.ScrollBar.Part)                    /*Appropriate action is taken                    */
  1005.             {                                                                        /*    according to the part of the            */
  1006.                                                                                     /*    scroll bar that was clicked…            */
  1007.             case inUpButton:                                         /*                                                                        */
  1008.               SetScrollBarVal(Poll.ScrollBar.Num, max(GetScrollBarMin(Poll.ScrollBar.Num), GetScrollBarVal(Poll.ScrollBar.Num) - 1));
  1009.               break;                                                        /*                                                                        */
  1010.             case inPageUp:                                            /*                                                                        */
  1011.               SetScrollBarVal(Poll.ScrollBar.Num, max(GetScrollBarMin(Poll.ScrollBar.Num), GetScrollBarVal(Poll.ScrollBar.Num) - 10));
  1012.                     break;                                                        /*                                                                        */
  1013.              case inDownButton:                                    /*                                                                        */
  1014.               SetScrollBarVal(Poll.ScrollBar.Num, min(GetScrollBarMax(Poll.ScrollBar.Num), GetScrollBarVal(Poll.ScrollBar.Num) + 1));
  1015.                     break;                                                        /*                                                                        */
  1016.              case inPageDown:                                        /*                                                                        */
  1017.               SetScrollBarVal(Poll.ScrollBar.Num, min(GetScrollBarMax(Poll.ScrollBar.Num), GetScrollBarVal(Poll.ScrollBar.Num) + 10));
  1018.                     break;                                                        /*                                                                        */
  1019.                 case inThumb:                                                /*Ignore thumb movement                                */
  1020.                 break;                                                        /*                                                                        */
  1021.             }                                                                        /*                                                                        */
  1022.         break;                                                                /*    (end of scroll bar response)            */
  1023.  
  1024.  
  1025.         case doKeyDown:case doAutoKey:/* U s e r   T y p e d   a   K e y :    -    -    -    -    -    */
  1026.                                                                     /*If the active window has an active editing        */
  1027.                                                                     /*    field, it automatically processes most key    */
  1028.                                                                     /*    strokes.  In this example, we only check        */
  1029.                                                                     /*    for the Tab key, which is used to tab to        */
  1030.                                                                     /*    the next or previous field (Shift-Tab)…            */
  1031.             if ((Poll.Key.Chr == TabKey) && !(Poll.Modifiers.Bits.CmdKey || Poll.Modifiers.Bits.OptionKey || Poll.Modifiers.Bits.ControlKey))
  1032.                 {                                                                        /*If the Tab key was typed without the*/
  1033.                                                                                         /*    Command, Option or Control                */
  1034.                                                                                         /*    modifier keys, tab to the next /    */
  1035.                                                                                         /*    previous field.                                        */
  1036.                                                                                         /*        In a full-featured application,    */
  1037.                                                                                         /*    you would likely validate a field    */
  1038.                                                                                         /*    for errors before proceeding to        */
  1039.                                                                                         /*    the field clicked by the user. In    */
  1040.                                                                                         /*    this demo, no validation is done.    */
  1041.           SaveFieldString();                                    /*Save the field's edited text as the    */
  1042.                                                                                   /*    field's string.                                        */
  1043.           Field = ActiveFieldNumber();                /*Determine the active field number        */
  1044.           if (!Poll.Modifiers.Bits.ShiftKey)    /*TAB: to next field…                                    */
  1045.                Field = Field + 1 - 3 * (Field == 3);            /*Add 1.  If field=3, start        */
  1046.                                                                                                    /*    at 1 again.                                */
  1047.              else                                                                /*SHIFT-TAB: to previous field…                */
  1048.                     Field = Field - 1 + 3 * (Field == 1);            /*Subtract 1.  If field=1,        */
  1049.                                                                                                         /*    start at 3.                                */
  1050.              ActivateField(Field, teSelectAll);    /*Select all the text in the newly        */
  1051.                                                                                      /*    activated field.                                    */
  1052.                 }                                                                        /*                                                                        */
  1053.             break;                                                                /*                                                                        */
  1054.                 
  1055.         default:;                                                                /*All other events are ignored                */
  1056.          }                                                                                /*                                                                        */
  1057.      }                                                                                    /*                                                                        */
  1058.  
  1059.  
  1060.  
  1061.  
  1062. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  1063.  * A c t i o n   i n   D e m o   W i n d o w   3 :
  1064.  *    This routine responds to actions made by the user in demo window 3.  The
  1065.  *    actions include:
  1066.  *        • Clicking on an icon (Cursor Zone over the icon)
  1067.  *        • Clicking a radio button
  1068.  *
  1069.  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  1070. void ActionInWindow3 (void)
  1071.     {
  1072.   short                ClickedZone;                                    /*Cursor zone clicked by user                    */
  1073.   short                Button;                                                /*Button number counter                                */
  1074.  
  1075.  
  1076.   switch (Poll.What)                                                /*Determine what the user did (what        */
  1077.       {                                                                                /*    event)…                                                        */
  1078.  
  1079.          case doClick:                                /* U s e r   C l i c k e d   I n   T h e                    */
  1080.                                                                  /*        W i n d o w :                                                                */
  1081.                                                                 /*The only click we care about in this window is    */
  1082.                                                                 /*    if it occurs in either of the two icons…            */
  1083.         ResetMouseClicks();                                        /*Only 1st mouse-down is needed.            */
  1084.                                                                                     /*    Ignore the rest.                                    */
  1085.             ClickedZone = FindCursorZone(Poll.Mouse.Down[0].Where);    /*Determine which        */
  1086.                                                                                         /*    cursor zone was clicked by the        */
  1087.                                                                                         /*    user.                                                            */
  1088.          if ((ClickedZone != 0) && (ClickedZone != MidiPort))    /*If a Cursor Zone        */
  1089.                 {                                                                        /*    was clicked, and the clicked zone    */
  1090.                                                                                      /*    is different from the currently        */
  1091.                                                                                      /*    selected MIDI port (ie: it was        */
  1092.                                                                                      /*    changed)…                */
  1093.                 if (ClickedZone == PrinterIcon)            /*Depending on which icon was clicked,*/
  1094.                     MidiPort = PrinterIcon;                        /*    set the MidiPort variable to the    */
  1095.                                                                                         /*    selected icon.                                        */
  1096.            else                                                                /*                                                                        */
  1097.                MidiPort = ModemIcon;                            /*                                                                        */
  1098.                                                                                    /*Redraw the printer and modem icons    */
  1099.                                                                                    /*    as currently selected…                        */
  1100.                 DrawIcon(PrinterIcon, 20, 32, enabled, MidiPort == PrinterIcon);    /*            */
  1101.                 DrawIcon(ModemIcon, 65, 32, enabled, MidiPort == ModemIcon);            /*            */
  1102.                 }                                                                        /*                                                                        */
  1103.             break;                                                                /*                                                                        */
  1104.  
  1105.  
  1106.         case doButton:                            /* U s e r   C l i c k e d   A   B u t t o n :    -    */
  1107.             for (Button = MidiHalfMeg; Button<=MidiTwoMeg; Button++)    /*Cycle through        */
  1108.           SelectButton(Button, Button == Poll.Button.Num);                /*    all 3 speed        */
  1109.                                                                                   /*    buttons and set only the selected    */
  1110.                                                                                   /*    one.  Turn the others off.                */
  1111.             MidiSpeed = Poll.Button.Num;                    /*Keep track of the selected button        */
  1112.          break;                                                                /*                                                                        */
  1113.  
  1114.         default:;                                                                /*Ignore all other events                            */
  1115.       }                                                                                /*                                                                        */
  1116.     }                                                                                    /*                                                                        */
  1117.  
  1118.  
  1119.  
  1120.  
  1121. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  1122.  * A c t i o n   i n   D e m o   W i n d o w   4 :
  1123.  *    This routine responds to actions made by the user in demo window 4. This routine
  1124.  *    is here for cosmetic reasons only, and you can get rid of it if you want.
  1125.  *
  1126.  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  1127. void ActionInWindow4 (void)
  1128.     {
  1129.     }
  1130.  
  1131.  
  1132.  
  1133.  
  1134. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  1135.  * A c t i o n   i n   D e m o   W i n d o w   5 :
  1136.  *    This routine responds to actions made by the user in demo window 5.  The only
  1137.  *    thing the user can do is click the default OK button, which closes the window.
  1138.  *
  1139.  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  1140. void ActionInWindow5 (void)
  1141.     {
  1142.   if (Poll.What == doButton)                                /*If the user clicked a button…                */
  1143.         CloseTheWindow(DemoWindow5);                        /*    end this demo by closing its            */
  1144.     }                                                                                    /*    window.                                                        */
  1145.  
  1146.  
  1147.  
  1148.  
  1149. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  1150.  * A c t i o n   i n   D e m o   W i n d o w   6 :
  1151.  *    This routine responds to actions made by the user in demo window 6.  Dynamic
  1152.  *    Alerts take care of responding to any action from the user, so you don't have
  1153.  *    to write any code for it.  This routine is here for cosmetic reasons only, and
  1154.  *    you can get rid of it if you want.
  1155.  *
  1156.  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  1157. void ActionInWindow6 (void)
  1158.     {
  1159.     }
  1160.  
  1161.  
  1162.  
  1163.  
  1164. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  1165.  * A c t i o n   i n   D e m o   W i n d o w   7 :
  1166.  *    This routine responds to actions made by the user in demo window 7.  The only
  1167.  *    thing you can do is select an item in a pop-up menu.
  1168.  *
  1169.  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  1170. void ActionInWindow7 (void)
  1171.     {
  1172.     #define            SilentContinueAlert    -11500        /*Button definition for a "Continue"    */
  1173.                                                                                         /*    dynamic alert that doesn't beep        */
  1174.                                                                                         /*    the user.                                                    */    
  1175.     
  1176.   if (Poll.What = doPopUpMenu)                            /*The only thing you can do: use a        */
  1177.       {                                                                                /*    pop-up menu.                                            */
  1178.   
  1179.         switch (Poll.Menu.Num)                                    /*Determine which Pop-Up Menu was            */
  1180.             {                                                                            /*    selected…                                                    */
  1181.  
  1182.         case popMenu1: case popMenu5:                 /*Pop-Up Menus 1 and 5 use a bullet        */
  1183.                                                                                     /*    (•) to mark a selected item.            */
  1184.                 PopUpMark(Poll.Menu.Num, Poll.Menu.Item, DotChar);    /*Mark new selection    */
  1185.                 break;                                                                                            /*                                        */
  1186.                 
  1187.             case popMenu2: case popMenu3:                 /*Pop-Up Menus 2 and 3 use a check (√)*/
  1188.                                                                                         /*    to mark    a selected item.                    */
  1189.                 CheckPopUp(Poll.Menu.Num, Poll.Menu.Item, on);    /*Mark the new selection    */
  1190.                 break;                                                                                    /*                                                */
  1191.  
  1192.             case popMenu4:                                                 /*This menu is a "fixed title" pop-        */
  1193.                                                                                         /*    down menu. Such menus are usually    */
  1194.                                                                                         /*    used to "do some-thing now". This */
  1195.                                                                                         /*    demo just displays an alert.            */
  1196.                 AlertBox(WatersEdgeLogo, "\pYour application would do something now, such as displaying a dialog that lets the user specify formatting characteristics.", SilentContinueAlert);
  1197.                 break;                                                            /*                                                                        */
  1198.             }                                                                            /*                                                                        */
  1199.         }                                                                                /*                                                                        */
  1200.     }                                                                                    /*                                                                        */
  1201.  
  1202.  
  1203.  
  1204.  
  1205. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  1206.  * A c t i o n   i n   D e m o   W i n d o w   8 :
  1207.  *    There are three routines for responding to events in this window.  The first two
  1208.  *    are button value drawing routines that display a button's value.  They are
  1209.  *    called when the button is clicked, or when the window is refreshed.
  1210.  
  1211.  *    This routine displays a value in the tool bar.  It is called whenever the "plus"
  1212.  *    or "minus" buttons are used, and when the screen is refreshed.
  1213.  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  1214. void ActionInWindow8_DrawToolBarValue (void)
  1215.     {
  1216.     char                theNumber[5];                                    /*Button's value, string format                */
  1217.     
  1218.     
  1219.     stoa(ToolBarValue, theNumber);                        /*Convert tool bar number to a string    */
  1220.   TextFont(systemFont);                                            /*Set window's font to Chicago 12pt.    */
  1221.   TextSize(12);                                                            /*                                                                        */
  1222.   PenColorNormal();                                                    /*PEN: 1x1 size, black, patCopy mode    */
  1223.                                                                                     /*Draw the value in the window's tool    */
  1224.                                                                                     /*    bar with a frame around it…                */
  1225.   TextInBox(theNumber, 401, 6, 439, 22, teJustCenter, true);    /*                                    */
  1226.      }                                                                                                                        /*                                    */
  1227.  
  1228. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  1229.  *    This routine displays the value of the "Globe" button.  It is called whenever
  1230.  *    the "Globe" button is used, and when the screen is refreshed.
  1231.  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  1232. void ActionInWindow8_DrawGlobeValue (void)
  1233.     {
  1234.     short                ButtonValue;                                    /*Globe button's value                                */
  1235.     char                theNumber[6];                                    /*Button's value, string format                */
  1236.  
  1237.  
  1238.     ButtonValue = GetPictButtonVal(GlobeButton);    /*Get the "globe" button's value    */
  1239.   stoa(ButtonValue, theNumber);                            /*Convert to a string                                    */
  1240.     strcat(theNumber, "°");                                        /*Add degree symbol to end of string    */
  1241.   TextFont(systemFont);                                            /*Set window's font to Chicago 12pt.    */
  1242.   TextSize(12);                                                            /*                                                                        */
  1243.                                                                                       /*Draw value below the "globe" button    */
  1244.   TextInBox(theNumber, 408, 201, 448, 217, teJustRight, false);    /*                                */
  1245.     }                                                                                                                            /*                                */
  1246.  
  1247. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  1248.  *  This routine responds to actions made by the user in demo window 8.  This
  1249.  *    window contains mostly Picture Buttons, so the response is limited to the user
  1250.  *    clicking on these buttons.  Notice that the buttons are organized into different
  1251.  *    types: simple binary clusters, multi-stage buttons, radio button clusters, etc.
  1252.  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  1253. void ActionInWindow8 (void)
  1254.     {
  1255.     short                theButton;                                        /*Button counter                                            */
  1256.  
  1257.  
  1258.   switch (Poll.What)                                                /*Determine what the user did (what        */
  1259.         {                                                                                /*    type of event)…                                        */
  1260.  
  1261.  
  1262.         case doPopUpMenu:                                /*P o p - U p   M e n u   S e l e c t e d :        */
  1263.             PopUpMark(Poll.Menu.Num, Poll.Menu.Item, '√');    /*Check selected item                */
  1264.                                                                                                             /*    (others are unchecked)    */
  1265.             if (Poll.Menu.Num == ButtonSpeedMenu)    /*If this menu regulate's the "globe"    */
  1266.                                                                                         /*    button speed…                                            */
  1267.                 SetPictButtonAccel(GlobeButton, Poll.Menu.Item - 1);    /*Set the button's    */
  1268.                                                                                                                             /*acceleration curve*/
  1269.             break;                                                                                                    /*                                    */
  1270.  
  1271.         case doPictButton:                        /* P i c t u r e   B u t t o n   S e l e c t e d*/
  1272.         switch (Poll.Button.Num)        /* Determine which picture button was selected…    */
  1273.             {
  1274.                                                                                         /*This section demonstrates typical        */
  1275.                                                                                         /*    interaction with check boxes,            */
  1276.                                                                                         /*    radio button groups and push            */
  1277.                                                                                         /*    buttons.                                                    */
  1278.                 case LeftAlignButton: case CenterAlignButton:    /*                                                    */
  1279.                 case RightAlignButton: case JustifyButton:        /*                                                    */
  1280.                                                                                         /*Cycle through the group and turn off*/
  1281.                                                                                         /*    the one that weren't clicked            */
  1282.                                                                                         /*    (deselect them)…                                    */
  1283.                     for (theButton = LeftAlignButton; theButton<=JustifyButton; theButton++)
  1284.                         SelectPictButton(theButton, theButton == Poll.Button.Num);    /*                */
  1285.                     break;                                                                                                                /*                */
  1286.  
  1287.                                                                                         /*This is the simplest case for                */
  1288.                                                                                         /*    picture buttons, clickable icons…    */
  1289.                 case PrinterButton: case ModemButton:/*                                                                        */
  1290.                                                                                         /*Only 1 icon can be on, so turn the    */
  1291.                                                                                         /*    other one off…                                        */        
  1292.                     for (theButton = PrinterButton; theButton<=ModemButton; theButton++) /*    */
  1293.                         SelectPictButton(theButton, theButton == Poll.Button.Num);                 /*    */
  1294.                     break;                                                                                                                             /*    */
  1295.  
  1296.                                                                                         /*Tape Deck buttons: Because each            */
  1297.                 case RewindButton: case StopButton:        /*    button locks down (if required)    */
  1298.                 case FastFwdButton: case PauseButton:    /*    by itself, we just have to            */
  1299.                 case RecordButton: case PlayButton:        /*    deselect any other button that    */
  1300.                                                                                             /*    may be down…                                        */
  1301.                                                                                             /*Cycle through all the buttons…        */
  1302.                     for (theButton = RewindButton; theButton<=PlayButton; theButton++)    /*    */
  1303.                         if (theButton != Poll.Button.Num)    /*If this button was not clicked…        */
  1304.                             SelectPictButton(theButton, notSelected);    /*    deselect the button.    */
  1305.                     break;                                                                                /*                                                */    
  1306.  
  1307.  
  1308.                 case GlobeButton: case -GlobeButton:/*If the globe button was selected        */
  1309.                     ActionInWindow8_DrawGlobeValue();    /*    and/or held,show the new value.        */
  1310.                                                                                         /*    The negative case is for the            */
  1311.                                                                                         /*    decrementing side of the button.    */
  1312.                     break;                                                        /*                                                                        */
  1313.  
  1314.  
  1315.                 case PlusButton:                                         /*"Plus" button in window's tool bar:    */
  1316.                     if (ToolBarValue < 3200) {                /*If the current value is less that        */
  1317.                                                                                         /*    3200 (the upper limit)…                        */
  1318.                         ToolBarValue = ToolBarValue * 2;/*Double the "zoom factor"                        */
  1319.                         ActionInWindow8_DrawToolBarValue();    /*Redisplay the tool bar's number    */
  1320.                     }                                                                            /*                                                                */
  1321.                     break;                                                                /*                                                                */
  1322.  
  1323.                 case MinusButton:                                        /*"Minus" button in window's tool bar:*/
  1324.                     if (ToolBarValue > 25) {                    /*If the current value is greater than*/
  1325.                                                                                         /*    25 (the lower limit)…                            */
  1326.                         ToolBarValue = ToolBarValue / 2;/*Half the "zoom factor"                            */
  1327.                         ActionInWindow8_DrawToolBarValue();    /*Redisplay the tool bar's number    */
  1328.                     }                                                                            /*                                                                */
  1329.                     break;                                                                /*                                                                */
  1330.  
  1331.  
  1332.                 case DoneButton:                                         /*If user clicked the "Done" button…    */
  1333.                     CloseTheWindow(DemoWindow8);            /*    end this demo by closing window.    */
  1334.                     break;                                                        /*                                                                        */
  1335.  
  1336.                 default:                                                        /*Ignore all other buttons                        */
  1337.                     break;                                                        /*                                                                        */
  1338.                 }                                                                        /*                                                                        */
  1339.  
  1340.             default:;                                                            /*Ignore all other events                            */
  1341.             }                                                                            /*                                                                        */
  1342.     }                                                                                    /*                                                                        */
  1343.  
  1344.  
  1345.  
  1346.  
  1347. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  1348.  * A c t i o n   i n   D e m o   W i n d o w   9 :
  1349.  *    This routine responds to actions made by the user in demo window 9 (the Tool
  1350.  *    Bar).  You can select an item in Pop-Up Menu or click picture buttons, but the
  1351.  *    picture buttons don't do anything in this demo.
  1352.  *
  1353.  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  1354. void ActionInWindow9 (void)
  1355.     {
  1356.     short                theButton;                                        /*Button counter                                            */
  1357.     
  1358.         
  1359.   if (Poll.What == doPopUpMenu)                            /*If the pop-up menu was used…                */
  1360.         PopUpMark(Poll.Menu.Num, Poll.Menu.Item, '√');    /*    check selected item                */
  1361.                                                                                                         /*        (others are unchecked)    */
  1362.  
  1363.                                                                                         /*If one of the 4 "single selection"    */
  1364.                                                                                         /*    buttons was selected…                            */
  1365.   else if ((Poll.What == doPictButton) && (Poll.Button.Num >= LeftAlignButton) && (Poll.Button.Num <= JustifyButton)) {
  1366.                                                                                         /*Cycle through the group and turn off*/
  1367.                                                                                         /*    the ones that weren't clicked            */
  1368.                                                                                         /*    (deselect them)…                                    */
  1369.         for (theButton = LeftAlignButton; theButton <= JustifyButton; theButton++){        
  1370.         SelectPictButton(theButton, (theButton == Poll.Button.Num));
  1371.             }
  1372.         }
  1373.     }
  1374.  
  1375.  
  1376.  
  1377.  
  1378. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  1379.  * A c t i o n   i n   D e m o   W i n d o w   10 :
  1380.  *    This routine responds to actions made by the user in demo window 10 (a vertical
  1381.  *    palette).  All the user can do is click a picture button, but the picture
  1382.  *    buttons don't do anything in this demo.
  1383.  *
  1384.  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  1385. void ActionInWindow10 (void)
  1386.     {
  1387.     short                theButton;                                        /*Button counter                                            */
  1388.     
  1389.         
  1390.   if (Poll.What == doPictButton) {                    /*If user clicked on a picture button…*/        
  1391.                                                                                         /*Cycle through the group and turn off*/
  1392.                                                                                         /*    the ones that weren't clicked            */
  1393.                                                                                         /*    (deselect them)…                                    */
  1394.         for (theButton = VPaletteMinButton; theButton <= VPaletteMaxButton; theButton++){        
  1395.         SelectPictButton(theButton, (theButton == Poll.Button.Num));
  1396.         }
  1397.         }
  1398.     }
  1399.  
  1400.  
  1401.  
  1402.  
  1403. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  1404.  * A c t i o n   i n   D e m o   W i n d o w   11 :
  1405.  *    This routine responds to actions made by the user in demo window 11 (a
  1406.  *    horizontal palette).  All the user can do is click a picture button, but the
  1407.  *    picture buttons don't do anything in this demo.
  1408.  *
  1409.  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  1410. void ActionInWindow11 (void)
  1411.     {
  1412.     short                theButton;                                        /*Button counter                                            */
  1413.     
  1414.         
  1415.   if (Poll.What == doPictButton) {                    /*If user clicked on a picture button…*/        
  1416.                                                                                         /*Cycle through the group and turn off*/
  1417.                                                                                         /*    the ones that weren't clicked            */
  1418.                                                                                         /*    (deselect them)…                                    */
  1419.         for (theButton = HPaletteMinButton; theButton <= HPaletteMaxButton; theButton++){        
  1420.         SelectPictButton(theButton, (theButton == Poll.Button.Num));
  1421.         }
  1422.         }
  1423.     }
  1424.  
  1425.  
  1426.  
  1427.  
  1428.  
  1429.  
  1430.  
  1431. /***********************************************************************************
  1432.  ***********************************************************************************
  1433.  *  D r a w   D e m o   W i n d o w s '   C o n t e n t s :
  1434.  *    The following routines are used to draw a demo windows' contents.  They are
  1435.  *    invoked when a demo window is first opened, and when a demo window needs to be
  1436.  *    refreshed.  The contents includes text and lines.  It excludes Tools Plus
  1437.  *    objects such as Buttons, Scroll Bars, List Boxes, Editing Fields, etc.  Those
  1438.  *    objects are refreshed automatically.
  1439.  */
  1440.  
  1441.  
  1442.  
  1443. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  1444.  * D r a w   T e x t   i n   a   B o x :
  1445.  *    This generic routine performs an often used task of drawing text within a
  1446.  *    specified rectangle.
  1447.  *
  1448.  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  1449. void TextInBox (char Str[],                                    /*The string that's going to be drawn    */
  1450.        short left, short top, short right,     /*Box's co-ordinates                                    */
  1451.        short bottom,                                                /*                                                                        */
  1452.        short Justification,                                    /*Left-aligned, centered, or right-        */
  1453.                                                                                    /*    aligned.                                                    */
  1454.        Boolean withBox)                                            /*Draw a box around the text?                    */
  1455.     {
  1456.     Rect                Rectangle;                                        /*Box's co-ordinates specified as a        */
  1457.                                                                                       /*    rectangle.                                                */
  1458.  
  1459.  
  1460.   SetRect(&Rectangle, left, top, right, bottom);    /*Convert the specified co-            */
  1461.                                                                                                   /*    ordinates into a rectangle.    */
  1462.   TextBox(Str, strlen(Str), &Rectangle, Justification);    /*Draw the text in the        */
  1463.                                                                                                               /*    specified rectangle.    */
  1464.   if (withBox)                                                            /*If a box is needed around the text…    */
  1465.         FrameRect(&Rectangle);                                    /*    draw the rectangle around the            */
  1466.     }                                                                                    /*    text.                                                            */
  1467.  
  1468.  
  1469.  
  1470. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  1471.  * C o n v e r t   a   s h o r t   t o   a   s t r i n g :
  1472.  *    This generic routine converts a short number into a C string which can then be
  1473.  *    drawn on a window.
  1474.  *
  1475.  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  1476. void stoa (short theShort, char theString[])
  1477.     {
  1478.     short sign;                                                                /*The short's sign (positive/negative)*/
  1479.     short ByteCount;                                                    /*Byte counter in string                            */
  1480.     short ReverseByte;                                                /*Reverse byte counter in string            */
  1481.     short theChar;                                                        /*Single character in the string            */
  1482.  
  1483.     if ((sign = theShort) < 0)                                /*Take note of the short's sign                */            
  1484.         theShort = -theShort;                                        /*Make the number positive                        */
  1485.  
  1486.     ByteCount = 0;                                                        /*Initialize the bytes counter                */    
  1487.     do{                                                                                /*Generate digits in reverse order…        */
  1488.         theString[ByteCount++] = theShort % 10 + '0';    /*Get the next digit                        */
  1489.     } while ((theShort /= 10) > 0);                                    /*Delete digit                                    */
  1490.     if (sign < 0)                                                            /*If sign is negative…                                */
  1491.         theString[ByteCount++] = '-';                        /*    add a minus sign.                                    */
  1492.     theString[ByteCount] = '\0';                            /*Null-terminate the C string                    */
  1493.         
  1494.                                                                                         /*Reverse the string into the proper    */
  1495.                                                                                         /*    sequence of digits…                                */
  1496.     for (ByteCount = 0, ReverseByte = strlen(theString)-1; ByteCount < ReverseByte; ByteCount++, ReverseByte--){
  1497.         theChar = theString[ByteCount];
  1498.         theString[ByteCount] = theString[ReverseByte];
  1499.         theString[ReverseByte] = theChar;
  1500.     }        
  1501. }
  1502.  
  1503.  
  1504.  
  1505. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  1506.  * D r a w   a   G r o u p   B o x   w i t h   a   T i t l e :
  1507.  *    This generic routine performs an often used task of drawing a "Group Box" such
  1508.  *    as the kind that is seen around a radio-button group.  It also draws the
  1509.  *    group's title at the top of the box.  The box is drawn using the pen's current
  1510.  *    size, pattern and transfer mode.  The group's title is drawn using the window's
  1511.  *    current font, size, and style.    
  1512.  *
  1513.  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  1514.  void GroupBox (Str255 Str,                                    /*Group's name (Pascal string)                */
  1515.        short left, short top, short right,    /*Co-ordinates of the group's                    */
  1516.        short bottom)                                                /*    enclosing box.                                        */
  1517.     {
  1518.     Rect                Rectangle;                                        /*Box's co-ordinates specified as a        */
  1519.                                                                                         /*    rectangle.                                                */
  1520.     Rect                TextRect;                                            /*Enclosing ractangle where box will    */
  1521.                                                                                         /*    appear.                                                        */
  1522.     short                    Width;                                            /*Text's width (for centering it)            */
  1523.  
  1524.  
  1525.   SetRect(&Rectangle, left, top, right, bottom);    /*Convert the specified co-            */
  1526.                                                                                                   /*    ordinates into a rectangle.    */
  1527.   FrameRect(&Rectangle);                                        /*Draw the group's box                                */
  1528.   if (Str[0] != 0)                                                    /*If a string was included as the            */
  1529.       {                                                                                /*    group's title, it will be centered*/
  1530.                                                                                       /*    at the top…                                                */
  1531.       Width = StringWidth(Str);                                /*Calculate the text's width in                */
  1532.                                                                                       /*    pixels.                                                        */
  1533.     TextRect.left = (Rectangle.left + Rectangle.right) / 2 - (Width / 2) - 2;    /*    */
  1534.     TextRect.right = TextRect.left + Width + 4;    /*    Calculate a rectangle so that    */
  1535.     TextRect.top = Rectangle.top - 8;                        /*    it fits on the top edge of the*/
  1536.     TextRect.bottom = TextRect.top + 16;                /*    group's box.  It's wide enough*/
  1537.                                                                                             /*    for the title, plus a 2 pixel    */
  1538.                                                                                             /*    border on each side.                    */
  1539.     TextBox(&Str[1], Str[0], &TextRect, teJustCenter);    /*Draw the group's title    */
  1540.         }                                                                                                        /*                                                */
  1541.     }                                                                                                            /*                                                */
  1542.  
  1543.  
  1544.  
  1545.  
  1546. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  1547.  * D r a w   C o n t e n t s   o f   D e m o   W i n d o w   1 :
  1548.  *    This routine draws all the text and lines in demo window 1.  It is called when
  1549.  *    first creating the window and when the window needs to be refreshed.  Note that
  1550.  *    objects that are created by Tools Plus are refreshed automatically.
  1551.  *
  1552.  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  1553. void DrawWindow1Contents (void)
  1554.     {
  1555.                                                                                         /* C o m m e n t s    -    -    -    -    -    -    -    -    -    */
  1556.   PenPat(&gray);                                                        /*Use gray pattern for drawing framing*/
  1557.                                                                                       /*    boxes.                                                        */
  1558.   TextFont(geneva);                                                    /*Draw all comments using Geneva 9pt,    */
  1559.   TextSize(9);                                                            /*    plain style.                                            */
  1560.   TextFace(0);                                                            /*                                                                        */
  1561.                                                                                         /*Comments for left list box…                    */
  1562.   TextInBox("This left text list uses the standard system font, just like normal list boxes.", 38, 108, 236, 140, teJustLeft, false);
  1563.                                                                                         /*Comments for right list box…                */
  1564.   TextInBox("This one uses Geneva 9pt.  Each list box can have its own font.", 295, 108, 416, 150, teJustLeft, false);
  1565.                                                                                         /*Comments for Cursor Zones…                    */
  1566.   TextInBox("This is a \"Plus Cursor\" zone.  The cursor changes when entering this area.", 275, 150, 400, 189, teJustCenter, true);
  1567.   TextInBox("This is a \"Cross Cursor\" zone.  The cursor changes when entering this area.", 275, 193, 400, 232, teJustCenter, true);
  1568.                                                                                         /*Comments for mini-buttons…                    */
  1569.   TextInBox("These buttons are drawn in bold Geneva 9pt.  Many different fonts, sizes and styles can be used.", 120, 140, 240, 190, teJustLeft, false);
  1570.   PenSize(3, 3);                                                        /*Make the pen 3x3 pixels for a fatter*/
  1571.                                                                                       /*    line.                                                            */
  1572.   GroupBox("\p", 14, 137, 242, 192);                /*Draw a gray, fat box around the mini*/
  1573.                                                                                       /*    buttons.                                                    */
  1574.                                                                                         /*Comment at bottom of the window…        */
  1575.   TextInBox("Double-click a radio button or a line in a list box to mean “select this and click ‘OK’.”  (Note that the OK button flashes.)  This OPTION is easily implemented.", 5, 290, 420, 320, teJustCenter, false);
  1576.  
  1577.  
  1578.                                                                                         /* L i s t   B o x   T i t l e s    -    -    */
  1579.   TextFont(systemFont);                                            /*Set the window's font to Chicago        */
  1580.   TextSize(12);                                                            /*    12pt.                                                            */
  1581.   MoveTo(5, 19);                                                        /*Draw the word "Left" at local co-        */
  1582.   DrawString("\pLeft:");                                        /*    ordinates 5,19 for the left list    */
  1583.                                                                                       /*    box.                                                            */
  1584.   MoveTo(253, 19);                                                    /*Draw the word "Right" at local co-    */
  1585.   DrawString("\pRight:");                                        /*    ordinates 253,19 for the right        */
  1586.                                                                                       /*    list box.                                                    */
  1587.  
  1588.                                                                                         /* R a d i o   B u t t o n                        */
  1589.                                                                                         /*        G r o u p ' s   T i t l e    -    - -    */
  1590.   PenNormal();                                                            /*Reset pen pattern to black, and pen    */
  1591.                                                                                       /*    size to 1x1.                                            */
  1592.   GroupBox("\pChoose", 165, 212, 231, 273);    /*Draw a box around the radio button    */
  1593.   }                                                                                    /*    group and give the group a title.    */
  1594.  
  1595.  
  1596.  
  1597.  
  1598. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  1599.  * D r a w   C o n t e n t s   o f   D e m o   W i n d o w   2 :
  1600.  *    This routine draws all the text and lines in demo window 2.  It is called when
  1601.  *    first creating the window and when the window needs to be refreshed.  Note that
  1602.  *    objects that are created by Tools Plus are refreshed automatically.
  1603.  *
  1604.  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  1605. void DrawWindow2Contents (void)
  1606.     {
  1607.     Rect                        Rectangle;                                /*Rectangle for drawing comments            */
  1608.                                                                                         /*    (text).                                                        */
  1609.                                                                                       
  1610.  
  1611.                                                                                         /* Comment above fields    -    -    -    -    -    -    -    */
  1612.   TextFont(geneva);                                                    /*Draw all comments using Geneva 9pt.    */
  1613.   TextSize(9);                                                            /*                                                                        */
  1614.   PenPat(&gray);                                                        /*Any line drawing will be done with    */
  1615.                                                                                       /*    a gray pattern.                                        */
  1616.   TextInBox("Click the \"zoom box\" to zoom between the standard and user co-ordinates.\r\rThe scroll bars don't actually scroll anything in this demo.  But notice that they are automatically repositioned when you resize the window.", 10, 2, 191, 95, teJustLeft, false);
  1617.  
  1618.                                                                                         /* Comment for 1st field    -    -    -    -    -    -    */
  1619.   TextInBox("The first field is \"length limited.\"  It accepts a maximum of 30 characters, (the length of the field), and does not scroll or require word-wrap.", 220, 15, 375, 77, teJustLeft, false);
  1620.   SetRect(&Rectangle, 215, 10, 380, 82);        /*Define the outline around the                */
  1621.                                                                                       /*    comment.                                                    */
  1622.   FrameRect(&Rectangle);                                        /*Draw a gray box around the comment    */
  1623.   MoveTo(215, 46);                                                    /*Draw a gray line from the first            */
  1624.   LineTo(195, 105);                                                    /*    field to the box that was                    */
  1625.                                                                                       /*    previously completed.                            */
  1626.  
  1627.                                                                                         /* Comment for 2nd field    -    -    -    -    -    -    */
  1628.   TextInBox("The second field is a \"single-line\" editing field.  It scrolls to keep the selection in view, and does not require word wrap.", 220, 97, 375, 146, teJustLeft, false);
  1629.   SetRect(&Rectangle, 215, 92, 380, 151);        /*Define the outline around the                */
  1630.                                                                                       /*    comment.                                                    */
  1631.   FrameRect(&Rectangle);                                        /*Draw a gray box around the comment    */
  1632.   MoveTo(215, 126);                                                    /*Draw a gray line from the second        */
  1633.   LineTo(195, 126);                                                    /*    field to the box that was                    */
  1634.                                                                                       /*    previously completed.                            */
  1635.  
  1636.                                                                                         /* Comment for 3rd field    -    -    -    -    -    -    */
  1637.   TextInBox("The third field is a \"multiple-line\" editing field.  It scrolls to keep the selection in view, and uses word wrap to break long words.", 220, 166, 375, 215, teJustLeft, false);
  1638.   SetRect(&Rectangle, 215, 161, 380, 220);    /*Define the outline around the                */
  1639.                                                                                       /*    comment.                                                    */
  1640.   FrameRect(&Rectangle);                                        /*Draw a gray box around the comment    */
  1641.   MoveTo(215, 207);                                                    /*Draw a gray line from the third            */
  1642.   LineTo(195, 148);                                                    /*    field to the box that was                    */
  1643.                                                                                       /*    previously completed.                            */
  1644.  
  1645.                                                                                         /* Comments at bottom    -    -    -    -    -    -    -    -    */
  1646.   TextInBox("Try editing the text in the fields (above).  The Edit menu automatically works with the active field (check out the Undo!)", 10, 220, 200, 260, teJustLeft, false);
  1647.   TextInBox("Notice that each editing field can have its own font!", 220, 235, 375, 260, teJustLeft, false);
  1648.   }
  1649.  
  1650.  
  1651.  
  1652.  
  1653. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  1654.  * D r a w   C o n t e n t s   o f   D e m o   W i n d o w   3 :
  1655.  *    This routine draws all the text and lines in demo window 3.  It is called when
  1656.  *    first creating the window and when the window needs to be refreshed.  Note that
  1657.  *    objects that are created by Tools Plus are refreshed automatically.
  1658.  *
  1659.  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  1660. void DrawWindow3Contents (void)
  1661.     {
  1662.   TextFont(geneva);                                                    /*Comment at top of window (drawn in    */
  1663.   TextSize(9);                                                            /*    Geneva 9pt).                                            */
  1664.   TextInBox("This demo simulates MIDI Interface settings.  Click on an icon to select it.", 10, 100, 230, 200, teJustCenter, false);
  1665.   DrawIcon(PrinterIcon, 20, 32, enabled, MidiPort == PrinterIcon);    /*Redraw the    */
  1666.   DrawIcon(ModemIcon, 65, 32, enabled, MidiPort == ModemIcon);            /*    printer        */
  1667.                                                                                       /*    and modem icons as currently            */
  1668.                                                                                       /*    selected.                                                    */
  1669.   TextFont(systemFont);                                            /*Box and title around icon group and    */
  1670.   TextSize(12);                                                            /*    radio button group (drawin in            */
  1671.                                                                                       /*    Chicago 12 pt.)…                                    */
  1672.   GroupBox("\pPort", 7, 17, 111, 80);                /*Draw a box around the Printer and        */
  1673.                                                                                       /*    Modem icons, and give the group a    */
  1674.                                                                                       /*    title.                                                        */
  1675.   GroupBox("\pSpeed", 128, 17, 231, 80);        /*Draw a box around the interface            */
  1676.                                                                                       /*    Speed radio buttons, and give the    */
  1677.   }                                                                                    /*    group a title.                                        */
  1678.  
  1679.  
  1680.  
  1681.  
  1682. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  1683.  * D r a w   C o n t e n t s   o f   D e m o   W i n d o w   4 :
  1684.  *    This routine draws all the text in demo window 4.  It is called when first
  1685.  *    creating the window and when the window needs to be refreshed.
  1686.  *
  1687.  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  1688. void DrawWindow4Contents (void)
  1689.     {
  1690.   MoveTo(10, 21);                                                        /*This window has been previously set    */
  1691.                                                                                       /*    to draw characters using Chicago    */
  1692.                                                                                       /*    12 pt.                                                        */
  1693.   DrawString("\pA lengthy process is being simulated.");    /*Display the message        */
  1694.   MoveTo(10, 85);                                                        /*                                                                        */
  1695.   DrawString("\pType \x11-. to cancel the simulation.");    /*Note: \x11 is the            */
  1696.     }                                                                                                                /*    Command character.    */
  1697.  
  1698.  
  1699.  
  1700.  
  1701. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  1702.  * D r a w   C o n t e n t s   o f   D e m o   W i n d o w   5 :
  1703.  *    This routine draws all the text and pictures in demo window 5.  It is called
  1704.  *    when first creating the window and when the window needs to be refreshed.  This
  1705.  *    routine has the following unique routines:
  1706.  *        • Color-independent drawing (doesn't care about the monitor's settings)
  1707.  *        • Color-dependent drawing (different drawing dependent on number of colors,
  1708.  *          grays, or if black & white)
  1709.  *        • Multiple-monitor compatibility (each monitor can have different settings)
  1710.  *    The color PICTure looks good only in 256 colors, but it also looks good in 256
  1711.  *    shades of gray as well as 16 shades of gray (8 bit and 4 bit gray).  So this
  1712.  *    demo decides which PICTure to draw depending on the monitor's settings.
  1713.  *        NOTE:  Tools Plus may not recognize if you change your monitor settings while
  1714.  *    running your application in the development environment.  It will recognize the
  1715.  *    change when your application is compiled to be a stand- alone (double-clickable)
  1716.  *    application.
  1717.  *
  1718.  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  1719. void DrawWindow5Contents (void)
  1720.     {
  1721.   short                TheScreen;                                        /*Screen counter for multiple-screen    */
  1722.                                                                                       /*    drawing.                                                    */
  1723.     PicHandle        hPicture;                                            /*Handle to a PICTure resource                */
  1724.     Rect                viewRect;                                            /*Viewing rectangle for the picture        */
  1725.  
  1726.  
  1727.                                                                                         /*Color Independent Drawing:    - - - -    */
  1728.                                                                                         /*Drawing that doesn't care about the    */
  1729.                                                                                         /*    monitor's setting can be done            */
  1730.                                                                                         /*    before or after the color-                */
  1731.                                                                                         /*    dependent drawing.                                */
  1732.   TextInBox("This window demonstrates color-dependent, color-independent, and multiple-screen drawing.  Use the Monitors desk accessory to change the monitor’s settings.\r  If you have two monitors, drag the window across so that half is on each screen.", 10, 5, 300, 70, teJustLeft, false);
  1733.  
  1734.                                                                                         /*Color Dependent Drawing: - - - - - -*/
  1735.                                                                                         /*The following code is for drawing        */
  1736.                                                                                         /*    that depends on the number of            */
  1737.                                                                                         /*    available colors, shades of gray,    */
  1738.                                                                                         /*    or if the monitor is set to Black    */
  1739.                                                                                         /*    & White.  It also makes the                */
  1740.                                                                                         /*routine multiple-monitor compatible.*/
  1741.   for (TheScreen = 1; TheScreen <= NumberOfScreens(); TheScreen++)    /*Repeat            */
  1742.       {                                                                                /*    drawing once for each logical            */
  1743.                                                                                       /*    screen (monitor with different        */
  1744.                                                                                       /*    settings)…                                                */
  1745.     BeginUpdateScreen(TheScreen);                        /*Begin the update for this logical        */
  1746.                                                                                     /*    screen.  All drawing is limited        */
  1747.                                                                                     /*    (clipped) to the one logical            */
  1748.                                                                                     /*    screen.                                                        */
  1749.     if ((ScreenDepth() >= 8) || ((ScreenDepth() == 4) && (!ScreenHasColors())))
  1750.             hPicture = GetPicture(ColorPICT);            /*Use the color pictures only if 256    */
  1751.                                                                                         /*    colors or 16 shades of gray are        */
  1752.     else                                                                        /*    available (or better).  Otherwise,*/
  1753.             hPicture = GetPicture(BlackAndWhitePICT);    /*    use the Black & White                    */
  1754.                                                                                                 /*    equivalent.                                        */
  1755.     viewRect = (*hPicture)->picFrame;                /*Determine the picture's framing            */
  1756.                                                                                     /*    rectangle.                                                */
  1757.                                                                                         /*The picture's rectangle is in the        */
  1758.                                                                                         /*    local window co-ordinates of the    */
  1759.                                                                                         /*    application that created it, so        */
  1760.                                                                                         /*    convert it to the local co-                */
  1761.                                                                                         /*    ordinates of this demo window…        */
  1762.     OffsetRect(&viewRect, -viewRect.left, -viewRect.top);        /*                                        */
  1763.         OffsetRect(&viewRect, 30, 90);                    /*Offset the picture's rectangle such    */
  1764.                                                                                         /*    that it is drawn below the                */
  1765.                                                                                         /*    descriptive text.                                    */
  1766.     DrawPicture(hPicture, &viewRect);                /*Draw the picture in its destination    */
  1767.                                                                                     /*    rectangle.                                                */
  1768.     ReleaseResource((Handle)hPicture);            /*Release the resource to conserve        */
  1769.                                                                                     /*    memory.                                                        */
  1770.     EndUpdateScreen();                                            /*End the update to the current                */
  1771.     }                                                                                /*    logical screen.                                        */
  1772.     }                                                                                    /*                                                                        */
  1773.  
  1774.  
  1775.  
  1776.  
  1777. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  1778.  * D r a w   C o n t e n t s   o f   D e m o   W i n d o w   6 :
  1779.  *    Dynamic Alerts take care of all drawing, so you don't have to write any code
  1780.  *    for it.  This routine is here for cosmetic reasons only, and you can get rid
  1781.  *    of it if you want.
  1782.  *
  1783.  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  1784. void DrawWindow6Contents (void)
  1785.     {
  1786.     }
  1787.  
  1788.  
  1789.  
  1790.  
  1791. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  1792.  * D r a w   C o n t e n t s   o f   D e m o   W i n d o w   7 :
  1793.  *    This routine draws all the text and lines in demo window 7.  It is called when
  1794.  *    first creating the window and when the window needs to be refreshed.
  1795.  *
  1796.  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  1797. void DrawWindow7Contents (void)
  1798.     {
  1799.     Rect                        Rectangle;                                /*Rectangle for drawing comments            */
  1800.                                                                                         /*    (text).                                                        */
  1801.  
  1802.                                                                                         /* Comment for Pop-Up Menus    -    -    -    -    -    */
  1803.                                                                                         /*All comments use Geneva 9pt, as set    */
  1804.                                                                                         /*    when this window was first opened.*/
  1805.   PenPat(&gray);                                                        /*Any line drawing will be done with a*/
  1806.                                                                                       /*    gray pattern.                                            */
  1807.  
  1808.                                                                                         /* Comment for 1st Pop-Up Menu-    -    -    -    */
  1809.   TextInBox("This is a standard Pop-Up Menu.  Nothing special here, except that it’s really easy to do.", 235, 15, 380, 51, teJustLeft, false);
  1810.   SetRect(&Rectangle, 230, 12, 385, 55);        /*Define outline around the comment        */
  1811.   FrameRect(&Rectangle);                                        /*Draw a gray box around the comment    */
  1812.   MoveTo(215, 26);                                                    /*Draw a gray line from the first menu*/
  1813.   LineTo(230, 26);                                                    /*    to the box completed above.                */
  1814.  
  1815.                                                                                         /* Comment for 2nd Pop-Up Menu-    -    -    -    */
  1816.   TextInBox("This Pop-Up Menu has icons.  But unlike System-7’s pop-ups, the selected item’s icon can appear in the pop-up box.", 235, 65, 380, 113, teJustLeft, false);
  1817.   SetRect(&Rectangle, 230, 62, 385, 117);        /*Define outline around the comment        */
  1818.   FrameRect(&Rectangle);                                        /*Draw a gray box around the comment    */
  1819.   MoveTo(220, 76);                                                    /*Draw a gray line from the second        */
  1820.   LineTo(230, 76);                                                    /*    menu to the box completed above.    */
  1821.  
  1822.                                                                                         /* Comment for 3rd Pop-Up Menu-    -    -    -    */
  1823.   TextInBox("This Pop-Up Menu contains icons without any text.  It looks like a custom menu but it’s not.", 235, 125, 380, 161, teJustLeft, false);
  1824.   SetRect(&Rectangle, 230, 122, 385, 165);    /*Define outline around the comment        */
  1825.   FrameRect(&Rectangle);                                        /*Draw a gray box around the comment    */
  1826.   MoveTo(175, 136);                                                    /*Draw a gray line from the third menu*/
  1827.   LineTo(230, 136);                                                    /*    to the box completed above.                */
  1828.  
  1829.                                                                                         /* Comment for 4th Pop-Up Menu-    -    -    -    */
  1830.   TextInBox("This is a “Pop-Down” menu.  It’s like an on-screen pull-down menu, and is usually used to “do something now.”", 235, 185, 380, 233, teJustLeft, false);
  1831.   SetRect(&Rectangle, 230, 182, 385, 237);    /*Define outline around the comment        */
  1832.   FrameRect(&Rectangle);                                        /*Draw a gray box around the comment    */
  1833.   MoveTo(220, 196);                                                    /*Draw a gray line from the fourth        */
  1834.   LineTo(230, 196);                                                    /*    menu to the box completed above.    */
  1835.  
  1836.                                                                                         /* Comment for 5th Pop-Up Menu-    -    -    -    */
  1837.   TextInBox("Pop-Up Menus can use any font and size, and can be auto-sized for a perfect look.", 235, 245, 380, 281, teJustLeft, false);
  1838.   SetRect(&Rectangle, 230, 242, 385, 285);    /*Define outline around the comment        */
  1839.   FrameRect(&Rectangle);                                        /*Draw a gray box around the comment    */
  1840.   MoveTo(150, 246);                                                    /*Draw a gray line from the fifth menu*/
  1841.   LineTo(230, 246);                                                    /*    to the box box completed above.        */
  1842.     }
  1843.  
  1844.  
  1845.  
  1846.  
  1847. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  1848.  * D r a w   C o n t e n t s   o f   D e m o   W i n d o w   8 :
  1849.  *    This routine draws all the text and lines in demo window 8.  Tools Plus takes
  1850.  *    care of all the button drawing.  The band at the top of this window demonstrates
  1851.  *    how to make a tool bar in a window.
  1852.  *
  1853.  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  1854. void DrawWindow8Contents (void)
  1855.     {
  1856.     short                        TheScreen;                                /*Screen counter, multi-screen drawing*/
  1857.     Rect                        ToolBarRect;                            /*Rectangle for drawing toolbar                */
  1858.  
  1859.  
  1860.                                                                                         /*D r a w   T o o l B a r                            */
  1861.                                                                                         /*        B a c k g r o u n d …                        */
  1862.     SetRect(&ToolBarRect, -1, -1, 473, 29);        /*Define the toolbar's rectangle            */
  1863.                                                                                         /*Draw the toolbar gray if the monitor*/
  1864.                                                                                         /*    is set to 4-bits or better…                */
  1865.     for (TheScreen = 1; TheScreen<=NumberOfScreens(); TheScreen++)    /*Repeat drawing*/
  1866.         {                                                                                /*    once for each logical screen            */
  1867.                                                                                       /*    (monitor with different settings)…*/
  1868.         PenColorNormal();                                                /*PEN: 1 x 1 size, black, patCopy mode*/
  1869.     BeginUpdateScreen(TheScreen);                        /*Begin the update for this logical        */
  1870.                                                                                     /*    screen.  All drawing is limited        */
  1871.                                                                                     /*    (clipped) to the one logical            */
  1872.                                                                                     /*    screen.                                                        */
  1873.     if (ScreenDepth() >= 4)                                    /*If this logical screen is set to a    */
  1874.         {                                                                            /*    depth of 4-bits or more (16 colors*/
  1875.                                                                                     /*    or grays)…                                                */
  1876.       RGBForeColor(&ToolBarGray);                        /*                                                                        */
  1877.       PaintRect(&ToolBarRect);                            /*Paint the toolbar the medium dark        */
  1878.         }                                                                            /*    gray.                                                            */
  1879.         EndUpdateScreen();                                            /*End the update to the current                */
  1880.     }                                                                                    /*    logical screen                                        */
  1881.   PenColorNormal();                                                    /*PEN: 1 x 1 size, black, patCopy mode*/
  1882.   FrameRect(&ToolBarRect);                                    /*Draw a black 1-pixel frame around        */
  1883.                                                                                       /*    the toolbar.                                            */
  1884.  
  1885.                                                                                         /*B u t t o n ' s   V a l u e s                */
  1886.   ActionInWindow8_DrawToolBarValue();                /*Draw value in the window's tool bar    */
  1887.   ActionInWindow8_DrawGlobeValue();                    /*Draw the globe button's value                */
  1888.  
  1889.   TextFont(geneva);                                                    /*All comments drawn using Geneva font*/
  1890.   TextSize(12);                                                            /*One comment is drawin in Geneva 9pt…*/
  1891.   MoveTo(6, 134);                                                        /*                                                                        */
  1892.   DrawString("\pPicture Buttons are very versatile.  You define their look and behavior.");
  1893.   PenPat(&gray);                                                        /*Any line drawing will be done with a*/
  1894.                                                                                       /*    gray pattern                                            */
  1895.   MoveTo(0, 118);                                                        /*Draw gray line dividing upper and        */
  1896.   LineTo(472, 118);                                                    /*    lower part of the window.                    */
  1897.   TextSize(9);                                                            /*All other comments use Geneva 9pt.    */
  1898.  
  1899.                                                                                         /* C o m m e n t   f o r   A r r o w    */
  1900.                                                                                         /*        B u t t o n s …                                    */
  1901.   TextInBox("These buttons use an icon for each stage, giving you absolute control over their appearance.", 10, 41, 155, 80, teJustLeft, false);
  1902.   MoveTo(120, 29);                                                    /*Draw a gray line from this comment    */
  1903.   LineTo(120, 40);                                                    /*    to the buttons it refers to.            */
  1904.  
  1905.                                                                                         /* C o m m e n t   f o r                            */
  1906.                                                                                         /*    A l i g n m e n t   B u t t o n s…*/
  1907.   TextInBox("These “SICN 3D” buttons are available in two sizes.  They use a single icon each.  Tools Plus does all the 3D drawing.  Activate another window and see how they look disabled.", 167, 41, 358, 110, teJustLeft, false);
  1908.   MoveTo(218, 29);                                                    /*Draw a gray line from this comment    */
  1909.   LineTo(218, 40);                                                    /*    to the buttons it refers to.            */
  1910.   MoveTo(322, 29);                                                    /*                                                                        */
  1911.   LineTo(322, 40);                                                    /*                                                                        */
  1912.  
  1913.                                                                                         /* C o m m e n t   f o r                            */
  1914.                                                                                         /*    U t i l i t y   B u t t o n s …        */
  1915.   TextInBox("This pair of buttons behaves as one control.  Continuous events are generated while the mouse button is held down.", 368, 41, 471, 118, teJustLeft, false);
  1916.   MoveTo(450, 29);                                                    /*Draw a gray line from this comment    */
  1917.   LineTo(450, 40);                                                    /*    to the buttons it refers to.            */
  1918.  
  1919.                                                                                         /* C o m m e n t   f o r   P l a i n    */
  1920.                                                                                         /*    I c o n   B u t t o n s …                    */
  1921.   TextInBox("Use picture buttons for clickable icons.", 19, 191, 111, 216, teJustLeft, false);
  1922.  
  1923.                                                                                         /* C o m m e n t   f o r   T a p e        */
  1924.                                                                                         /*    D e c k   B u t t o n s …                    */
  1925.   TextInBox("Professional looking controls are easy!", 20, 281, 117, 306, teJustLeft, false);
  1926.  
  1927.                                                                                         /* C o m m e n t   f o r                            */
  1928.                                                                                         /*    S c r o l l i n g   B u t t o n …    */
  1929.   TextInBox("These buttons have “values” associated with them.  You can raise/lower the value by clicking on opposite sides of the button.  The left button uses only 1 icon!", 204, 154, 398, 203, teJustLeft, false);
  1930.   MoveTo(147, 158);                                                    /*                                                                        */
  1931.   DrawString("\pStep");                                            /*                                                                        */
  1932.   MoveTo(172, 158);                                                    /*                                                                        */
  1933.   DrawString("\pScroll");                                        /*                                                                        */
  1934.  
  1935.                                                                                         /* C o m m e n t   f o r   D u a l -    */
  1936.                                                                                         /*    S t a g e   B u t t o n    …                    */
  1937.     TextInBox("These dual-stage buttons toggle when selected.", 221, 243, 342, 268, teJustLeft, false);
  1938. }                                                                                        /*                                                                        */        
  1939.  
  1940.  
  1941.  
  1942.  
  1943. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  1944.  * D r a w   C o n t e n t s   o f   D e m o   W i n d o w   9 :
  1945.  *    This routine draws the contents of demo window 9 (the Tool Bar).  In this demo,
  1946.  *    the only thing the Tool Bar needs is to be painted with the correct color (gray
  1947.  *    when the monitor is set to 4 bits or higher).
  1948.  *
  1949.  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  1950. void DrawWindow9Contents (void)
  1951.     {
  1952.     Rect                        ToolBarRect;                            /*Rectangle for drawing toolbar                */
  1953.  
  1954.  
  1955.                                                                                         /* P a i n t   T o o l B a r   G r a y*/
  1956.   if (ScreenDepth() >= 4)                                        /*If main minitor is set to a depth of*/
  1957.       {                                                                                /*    4-bits or more (16 colors/grays),    */
  1958.                                                                                       /*    paint the tool bar…                                */
  1959.     RGBForeColor(&ToolBarGray);                            /*Set the foregound color to gray            */
  1960.     SetRect(&ToolBarRect, 0, 0, 32000, 32000);/*Define the toolbar's rectangle        */
  1961.                                                                                     /*    (who cares how big it really is?    */
  1962.                                                                                     /*    All drawing is limited to the Tool*/
  1963.                                                                                     /*    Bar).                                                            */
  1964.     PaintRect(&ToolBarRect);                                /*Paint tool bar the medium dark gray    */
  1965.         }
  1966.     }
  1967.  
  1968.  
  1969.  
  1970.  
  1971. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  1972.  * D r a w   C o n t e n t s   o f   D e m o   W i n d o w   10 :
  1973.  *    This floating palette contains only Tools Plus objects, so there is no need to
  1974.  *    draw anything in this window. This routine is here for cosmetic reasons only,
  1975.  *    and you can get rid of it if you want.
  1976.  *
  1977.  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  1978. void DrawWindow10Contents (void)
  1979.     {
  1980.     }
  1981.  
  1982.  
  1983.  
  1984.  
  1985. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  1986.  * D r a w   C o n t e n t s   o f   D e m o   W i n d o w   11 :
  1987.  *    This floating palette contains only Tools Plus objects, so there is no need to
  1988.  *    draw anything in this window. This routine is here for cosmetic reasons only,
  1989.  *    and you can get rid of it if you want.
  1990.  *
  1991.  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  1992. void DrawWindow11Contents (void)
  1993.     {
  1994.     }
  1995.  
  1996.  
  1997.  
  1998.  
  1999.  
  2000.  
  2001.  
  2002.  
  2003.  
  2004.  
  2005. /***********************************************************************************
  2006.  ***********************************************************************************
  2007. /*  C r e a t e   D e m o   W i n d o w s :
  2008.  *    The following routines are used to create each of the demo windows and their
  2009.  *    contents.  These routines are invoked when the user selects an item in the
  2010.  *    Demos menu.  A couple of these windows are opened automatically by the
  2011.  *    "PrepareTheDemo" routine when this program starts up.
  2012.  */
  2013.  
  2014.  
  2015.  
  2016. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  2017.  * C r e a t e   D e m o   W i n d o w   1 :
  2018.  *    This window demonstrates how Tools Plus works with  List Boxes, Buttons (radio
  2019.  *    buttons, check boxes and push buttons), and Cursor Zones.
  2020.  *        When playing around with this window, try the following things:
  2021.  *            • double-click a line in a List Box and notice how it translates to "select
  2022.  *                this line and OK"
  2023.  *            • press the Enter or Return key to activate the default OK button
  2024.  *            • activate another window and notice all the buttons and list boxes get
  2025.  *                disabled.  Also notice that the black outline around the default OK button
  2026.  *                gets dimmed out too!
  2027.  *    TIP:  To make this window appear to fill in as quickly as possible, we don't
  2028.  *                populate the list boxes until the end!
  2029.  *
  2030.  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  2031. void OpenDemoWindow1 (void)
  2032.     {                                                                                    /*Open the window (it automatically        */
  2033.                                                                                         /*    shifts down to compensate for an    */
  2034.                                                                                         /*    open Tool Bar, and its position is*/
  2035.                                                                                         /*    "tiled")…                                                    */
  2036.     WindowOpen(DemoWindow1, 0, 0, 425, 320, "\pLists, Buttons and Cursor Zones", noGrowDocProc + wTile, GoAway, NotModal);
  2037.                                                                                         /* Left List Box:    -    -    -    -    -    -    -    -    -    -    */
  2038.   TextFont(systemFont);                                            /*Create an empty list box.  Its font    */
  2039.   TextSize(12);                                                            /*    will be the window's current font:*/
  2040.   NewListBox(LeftList, 40, 8, 220, 104, lOnlyOne);    /*    Chicago 12 pt.                        */
  2041.                                                                                         /* Right List Box:-    -    -    -    -    -    -    -    -    -    */
  2042.   TextFont(geneva);                                                    /*Create a second empty list box.            */
  2043.   TextSize(9);                                                            /*    This one will use Geneva 9pt to        */
  2044.                                                                                       /*    show that a different font can be    */
  2045.   NewListBox(RightList, 295, 8, 400, 104, lOnlyOne);    /*    used per list box.            */
  2046.                                                                                         /* B u t t o n s :-    -    -    -    -    -    -    -    -    -    */
  2047.   TextFace(bold);                                                        /*Buttons will be drawn in bold                */
  2048.                                                                                       /*    Geneva 9pt.                                                */
  2049.                                                                                         /*Create a set of mini-fonts using        */
  2050.                                                                                         /*    Geneva 9pt in bold typeface.  This*/
  2051.                                                                                         /*    demonstrates the use of a second    */
  2052.                                                                                         /*    font for buttons.                                    */
  2053.   NewButton(MiniButton1, 20, 150, 35, 166, "\p1", pushButProc + useWFont, enabled, notSelected);
  2054.   NewButton(MiniButton2, 40, 150, 55, 166, "\p2", pushButProc + useWFont, enabled, notSelected);
  2055.   NewButton(MiniButton3, 60, 150, 75, 166, "\p3", pushButProc + useWFont, enabled, notSelected);
  2056.   NewButton(MiniButton4, 80, 150, 95, 166, "\p4", pushButProc + useWFont, enabled, notSelected);
  2057.   NewButton(MiniButton5, 100, 150, 115, 166, "\p5", pushButProc + useWFont, enabled, notSelected);
  2058.                                                                                         /*Create a set of check boxes using        */
  2059.                                                                                         /*    the System font (Chicago 12)…            */
  2060.   NewButton(CheckBox1, 20, 220, 117, 236, "\pFirst Choice", checkBoxProc, enabled, notSelected);
  2061.   NewButton(CheckBox2, 20, 236, 133, 252, "\pSecond Choice", checkBoxProc, enabled, selected);
  2062.   NewButton(CheckBox3, 20, 252, 134, 268, "\pTwo And Three", checkBoxProc, enabled, selected);
  2063.                                                                                         /*Create a set of radio buttons using    */
  2064.                                                                                         /*    the System font (Chicago 12)…            */
  2065.   NewButton(RadioButton1, 170, 220, 214, 236, "\pOne", radioButProc, enabled, selected);
  2066.   NewButton(RadioButton2, 170, 236, 216, 252, "\pTwo", radioButProc, enabled, notSelected);
  2067.   NewButton(RadioButton3, 170, 252, 226, 268, "\pThree", radioButProc, enabled, notSelected);
  2068.                                                                                         /*Create the "Cancel" push-button…        */
  2069.   NewButton(CancelButton, 275, 250, 335, 270, "\pCancel", pushButProc, enabled, notSelected);
  2070.                                                                                         /*Create the "OK" push-button.  This    */
  2071.                                                                                         /*    is the window's default button,        */
  2072.                                                                                         /*    and it is selected automatically    */
  2073.                                                                                         /*    when you press Return or Enter…        */
  2074.   NewButton(OkButton, 350, 250, 410, 270, "\pOK", DefaultButton, enabled, notSelected);
  2075.  
  2076.   DrawWindow1Contents();                                        /*Draw the rest of the objects in this*/
  2077.                                                                                       /*    demo window.  All Tools Plus            */
  2078.                                                                                       /*    objects are auto matically updated*/
  2079.                                                                                       /*    when a window needs to be                    */
  2080.                                                                                       /*    refreshed, such as when you bring    */
  2081.                                                                                       /*    it to the front to make it active.*/
  2082.                                                                                         /*        Non-Tools Plus objects (ie:            */
  2083.                                                                                         /*    those you create) have to be            */
  2084.                                                                                         /*    redrawn separately in response to    */
  2085.                                                                                         /*    a doRefresh event, so it's a good    */
  2086.                                                                                         /*    idea to keep them in a separate        */
  2087.                                                                                         /*    routine.                                                    */
  2088.  
  2089.     /* T i m e   c o n s u m i n g   t h i n g s …                                                                    */
  2090.     /*    The following time-consuming things were saved for the end of the routine        */
  2091.     /*    because it makes the window appear to be filled in faster, particularly on    */
  2092.     /*    slower Macs like the Plus, Classic, or LC.  You don't have to follow the        */
  2093.     /*    same concept when you write your own applications.                                                    */
  2094.                                                                                         /* Cursor Tables & Zones:    -    -    -    -    -    -    */
  2095.   NewCursorTable(1, arrowCursor);                        /*Create Cursor Table number 1.  The    */
  2096.                                                                                       /*    standard Arrow cursor is the            */
  2097.                                                                                       /*    default for this table.                        */
  2098.                                                                                       
  2099.   CursorZone(1, 1, plusCursor, 275, 150, 400, 189);        /*Add two Cursor Zones to        */
  2100.   CursorZone(1, 2, crossCursor, 275, 193, 400, 232);    /*    the Cursor Table.        When*/
  2101.                                                                                       /*    the cursor is in these zones, it    */
  2102.                                                                                       /*    will automatically change to the    */
  2103.                                                                                       /*    specified cursor shape.                        */
  2104.   UseCursorTable(1);                                                /*The current window will use Cursor    */
  2105.                                                                                       /*    Table no 1.  Note that a cursor        */
  2106.                                                                                       /*    table exists independently of            */
  2107.                                                                                       /*    windows.  In fact, several windows*/
  2108.                                                                                       /*    can each use the same cursor            */
  2109.                                                                                       /*    table.  It is not necessary to        */
  2110.                                                                                       /*    create a cursor table each time        */
  2111.                                                                                       /*    you want a window to use it.  You */
  2112.                                                                                       /*    just use the UseCursorTable                */
  2113.                                                                                       /*    routine to make a window use a        */
  2114.                                                                                       /*    cursor table.                                            */
  2115.                                                                                       
  2116.                                                                                         /* Fill List Boxes:    -    -    -    -    -    -    -    -    -    */
  2117.   DrawListBox(LeftList, off);                                /*Turn list box drawing off for both    */
  2118.   DrawListBox(RightList, off);                            /* boxes.  The    contents will be drawn*/
  2119.                                                                                       /*    later.  If you don't turn list box*/
  2120.                                                                                       /*    drawing off while adding lines,        */
  2121.                                                                                         /*    you will see each line being            */
  2122.                                                                                         /*    added, one at a time.  This way,    */
  2123.                                                                                         /*    you see all the lines appear at        */
  2124.                                                                                         /*    once.                                                            */
  2125.                                                                                         /*Fill the lines in the left list box.*/
  2126.                                                                                         /*    You can fill these lines in any        */
  2127.                                                                                         /*    order you want.  Notice the longer*/
  2128.                                                                                         /*    lines are compressed (the                    */
  2129.                                                                                         /*    characters are closer together)        */
  2130.                                                                                         /*    when using System 7.  Tools Plus    */
  2131.                                                                                         /*    automatically appends the ellipsis*/
  2132.                                                                                         /*    (…) if the line's text is too long*/
  2133.                                                                                         /*    to see in the list.  Fill in the    */
  2134.                                                                                         /*    lines in the right list box.  The    */
  2135.                                                                                         /*    Tools Plus User Manual describes    */
  2136.                                                                                         /*    how you can populate a list box        */
  2137.                                                                                         /*    and have the lines in alphabetic    */
  2138.                                                                                         /*    order.                                                        */
  2139.   SetListBoxText(LeftList, 1, "\pBill Arlington, Shipping & Receiving");    /*            */
  2140.   SetListBoxText(LeftList, 2, "\pGail Force, Social Director");    /*                                */
  2141.   SetListBoxText(LeftList, 3, "\pBill Gates, Comedy Relief");        /*                                */
  2142.   SetListBoxText(LeftList, 4, "\pRon Martin, Art & Graphics");    /*                                */
  2143.   SetListBoxText(LeftList, 5, "\pSamantha Moore, Connectivity");/*                                */
  2144.   SetListBoxText(LeftList, 6, "\pMike Simms, Design");                    /*                                */
  2145.   SetListBoxText(LeftList, 7, "\pSam Strong, Design");                    /*                                */
  2146.   SetListBoxText(LeftList, 8, "\pLinda Tyler, Drafting");                /*                                */
  2147.   SetListBoxText(LeftList, 9, "\pMargaret Victor, Drafting");        /*                                */
  2148.   SetListBoxText(RightList, 1, "\pArt & Graphics");                            /*                                */
  2149.   SetListBoxText(RightList, 2, "\pConnectivity");                                /*                                */
  2150.   SetListBoxText(RightList, 3, "\pComedy Relief");                            /*                                */
  2151.   SetListBoxText(RightList, 4, "\pDesign");                                            /*                                */
  2152.   SetListBoxText(RightList, 5, "\pDrafting");                                        /*                                */
  2153.   SetListBoxText(RightList, 6, "\pShipping & Receiving");                /*                                */
  2154.   SetListBoxText(RightList, 7, "\pSocial Director");                        /*                                */
  2155.   SetListBoxLine(LeftList, 2, on);                    /*Select the left list's second line    */
  2156.                                                                                       /*    by default.                                                */
  2157.   DrawListBox(LeftList, on);                                /*Turn on line drawing for both list    */
  2158.   DrawListBox(RightList, on);                                /*    boxes. Their contents are drawn by*/
  2159.                                                                                       /*    this process.                                            */
  2160.   EnableMenu(FileMenu, CloseItem, enabled);    /*Enable the File menu's Close                */
  2161.                                                                                       /*    command, now that there's a window*/
  2162.   }                                                                                    /*    to close.                                                    */
  2163.  
  2164.  
  2165.  
  2166.  
  2167. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  2168.  * C r e a t e   D e m o   W i n d o w   2 :
  2169.  *    This window demonstrates how Tools Plus works with  Editing Fields, Window
  2170.  *    Zooming and Scroll Bars.  Please note that although this window has scroll bars,
  2171.  *    the demo doesn't actually scroll anything.  Notice that when you click the
  2172.  *    window's zoom box, or when you resize the window by using the size box, that
  2173.  *    the scroll bars are automatically moved to accommodate the window's new size.
  2174.  *        When playing around with this window, try the following things:
  2175.  *            • click the window's zoom box to zoom between the standard co-ordinates
  2176.  *                and the user-defined ones
  2177.  *            • use the size box to resize the window.  Notice that the minimum and
  2178.  *                maximum size are controlled
  2179.  *            • type in the first (length limited) field
  2180.  *            • copy and paste test between another application or desk accessory and
  2181.  *                one of the fields
  2182.  *
  2183.  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  2184. void OpenDemoWindow2 (void)
  2185.     {
  2186.   Rect                userRect, stdRect;                        /*User co-ordinates and standard co-    */
  2187.                                                                                       /*    ordinates used for zooming one of    */
  2188.                                                                                       /*    the demo windows.                                    */
  2189.  
  2190.     
  2191.                                                                                         /* C r e a t e   t h e   W i n d o w:    */
  2192.                                                                                         /*Open the window (it automatically        */
  2193.                                                                                         /*    shifts down to compensate for an    */
  2194.                                                                                         /*    open Tool Bar, and its position is*/
  2195.                                                                                         /*    "tiled")…                                                    */
  2196.   WindowOpen(DemoWindow2, 20, 58, 420, 338, "\pFields, Zooming and Scroll Bars", documentProc + ZoomBox + wTile, GoAway, NotModal);
  2197.   GetWindowZoom(&userRect, &stdRect);                /*Get the standard and user-defined        */
  2198.                                                                                       /*    co-ordinates for Zooming the            */
  2199.                                                                                       /*    window (using zoom box)                        */
  2200.   SetRect(&userRect, 250, 100, 470, 320);        /*Define the window's "user- defined"    */
  2201.                                                                                       /*    co-ords that are used for Zooming    */
  2202.                                                                                       /*    the window when the zoom-box is        */
  2203.                                                                                       /*    clicked.                                                    */
  2204.   SetWindowZoom(&userRect, &stdRect);                /*Set the standard and user-defined        */
  2205.                                                                                       /*    co-ordinates for Zooming.                    */
  2206.   SetWindowSizeLimits(220, 220, 400, 280);    /*Set the window's sizing limits:            */
  2207.                                                                                         /*    minHoriz, minVert, maxHoriz,            */
  2208.                                                                                         /*    maxVert.                                                    */
  2209.                                                                                         /* Scroll Bars:    -    -    -    -    -    -    -    -    -    -    -    */
  2210.   NewScrollBar(RightBar, scrlRightEdge, scrlTopEdge, scrlRightEdge, scrlBottomEdge, enabled, 1, 5, 10);
  2211.   NewScrollBar(BottomBar, scrlLeftEdge, scrlBottomEdge, scrlRightEdge, scrlBottomEdge, enabled, 1, 50, 100);
  2212.                                                                                       /*    scroll bar for the window.  The        */
  2213.                                                                                       /*    last three parameters specify the    */
  2214.                                                                                       /*    min limit, current value, and max    */
  2215.                                                                                       /*    limit.                                                        */
  2216.  
  2217.                                                                                         /* E d i t i n g   F i e l d s :    -    -    */
  2218.                                                                                       /*Specify the text that will be appear*/
  2219.                                                                                       /*    in each field.                                        */
  2220.     Cstr2PHdl("Length limited field", hField1);                /*                                                        */
  2221.     Cstr2PHdl("Single line editing field.", hField2);    /*                                                        */    
  2222.     Cstr2PHdl("This is a multiple-line editing field which incorporates word wrap.", hField3);
  2223.  
  2224.   TextFont(monaco);                                                    /*First field uses Monaco 9pt font,        */
  2225.   TextSize(9);                                                            /*    and is length limited.  That means*/
  2226.   FieldLengthLimit(on);                                            /*    that no more than 30 characters        */
  2227.                                                                                     /*    (the field's limit) can be typed    */
  2228.                                                                                       /*    or pasted in the field.                        */
  2229.   NewField(1, 10, 100, 191, 111, hField1, teBoxNoCR, teJustLeft);    /*                            */
  2230.   FieldLengthLimit(off);                                        /*The remaining fields are not length    */
  2231.                                                                                          /*    limited.                                                    */
  2232.  
  2233.   TextFont(geneva);                                                    /*Second field uses bold Geneva 9pt.    */
  2234.      TextFace(bold);                                                        /*    This field demonstrates a single-    */
  2235.                                                                                          /*    line editing field.                                */
  2236.   NewField(2, 10, 120, 191, 132, hField2, teBoxNoCR, teJustLeft);    /*                            */
  2237.  
  2238.   TextFont(systemFont);                                            /*Third field uses Chicago 12pt.  It    */
  2239.   TextSize(12);                                                            /*    demonstrates a multiple-line            */
  2240.   TextFace(0);                                                            /*    editing field with word wrap.            */
  2241.   NewField(3, 10, 141, 191, 189, hField3, teBoxCR, teJustLeft);    /*                                */
  2242.  
  2243.   ActivateField(1, teSelectEnd);                        /*Activate the first field, with the    */
  2244.                                                                                       /*    insertion point at the end of the    */
  2245.                                                                                       /*    text.                                                            */
  2246.   DrawWindow2Contents();                                        /*Draw the rest of the objects in this*/
  2247.                                                                                       /*    demo window.  All Tools Plus            */
  2248.                                                                                       /*    objects are auto matically updated*/
  2249.                                                                                       /*    when a window needs to be                    */
  2250.                                                                                       /*    refreshed, such as when you bring    */
  2251.                                                                                       /*    it to the front to make it active.*/
  2252.                                                                                         /*        Non-Tools Plus objects (ie:            */
  2253.                                                                                         /*    those you create) have to be            */
  2254.                                                                                         /*    redrawn separately in response to    */
  2255.                                                                                         /*    a doRefresh event, so it's a good    */
  2256.                                                                                         /*    idea to keep them in a separate        */
  2257.                                                                                         /*    routine.                                                    */
  2258.   EnableMenu(FileMenu, CloseItem, enabled);    /*Enable the File menu's Close                */
  2259.                                                                                       /*    command, now that there's a window*/
  2260.   }                                                                                    /*    to close.                                                    */
  2261.  
  2262.  
  2263.  
  2264.  
  2265. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  2266.  * C r e a t e   D e m o   W i n d o w   3 :
  2267.  *    This window demonstrates shows how Tools Plus can draw icon families (in
  2268.  *    System 6 and System 7).  It also provides an example how to use Cursor Zones
  2269.  *    to make icons click-sensitive.
  2270.  *        When playing around with this window, try the following things:
  2271.  *            • click either of the two icons
  2272.  *            • if you have a color monitor, use the Monitors control panel to change
  2273.  *                the number of colors displayed
  2274.  *            • if you have two monitors, set one to black and white and drag the window
  2275.  *                such that the icon is half on a color screen and half on a black and
  2276.  *                white screen.  Tools Plus draws the icon perfectly.
  2277.  *
  2278.  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  2279. void OpenDemoWindow3 (void)
  2280.     {                                                                                    /*Open the window (it automatically        */
  2281.                                                                                         /*    shifts down to compensate for an    */
  2282.                                                                                         /*    open Tool Bar, and its position is*/
  2283.                                                                                         /*    "tiled")…                                                    */
  2284.   WindowOpen(DemoWindow3, 0, 0, 240, 142, "\pIcons and Cursor Zones", noGrowDocProc + wTile, GoAway, NotModal);
  2285.  
  2286.                                                                                         /* Cursor Table & Zones:-    -    -    -    -    -    -    */
  2287.   NewCursorTable(2, arrowCursor);                        /*Create Cursor Table number 2.  The    */
  2288.                                                                                       /*    standard Arrow cursor is the            */
  2289.                                                                                       /*    default for this table.                        */
  2290.   CursorZone(2, PrinterIcon, arrowCursor, 20, 32, 52, 64);    /*Add two Cursor Zones*/
  2291.   CursorZone(2, ModemIcon, arrowCursor, 65, 32, 97, 64);        /*    to the Cursor            */
  2292.                                                                                       /*    Table.  The user can click these    */
  2293.                                                                                       /*    zones, thereby making the Printer    */
  2294.                                                                                       /*    and Modem icons click sensitive.    */
  2295.   UseCursorTable(2);                                                /*The current window will use Cursor    */
  2296.                                                                                       /*    Table no 2.  Note that a cursor        */
  2297.                                                                                       /*    table exists independently of            */
  2298.                                                                                       /*    windows.  In fact, several windows*/
  2299.                                                                                       /*    can each use the same cursor            */
  2300.                                                                                       /*    table.  It is not necessary to        */
  2301.                                                                                       /*    create a cursor table each time        */
  2302.                                                                                       /*    you want a window to use it.  You    */
  2303.                                                                                       /*    just use the UseCursorTable                */
  2304.                                                                                       /*    routine to make a window use a        */
  2305.                                                                                       /*    cursor table.                                            */
  2306.  
  2307.                                                                                         /*Create 3 radio buttons used to            */
  2308.                                                                                         /*    select the MIDI interface's speed…*/
  2309.   NewButton(MidiHalfMeg, 142, 27, 216, 39, "\p  .5 MHz.", radioButProc, enabled, notSelected);
  2310.   NewButton(MidiOneMeg, 142, 43, 216, 55, "\p1.0 MHz.", radioButProc, enabled, notSelected);
  2311.   NewButton(MidiTwoMeg, 142, 58, 216, 72, "\p2.0 MHz.", radioButProc, enabled, notSelected);
  2312.   SelectButton(MidiSpeed, selected);                /*Set the current speed button                */
  2313.  
  2314.   DrawWindow3Contents();                                        /*Draw the rest of the objects in this*/
  2315.                                                                                       /*    demo window.  All Tools Plus            */
  2316.                                                                                       /*    objects are auto matically updated*/
  2317.                                                                                       /*    when a window needs to be                    */
  2318.                                                                                       /*    refreshed, such as when you bring    */
  2319.                                                                                       /*    it to the front to make it active.*/
  2320.                                                                                         /*        Non-Tools Plus objects (ie:            */
  2321.                                                                                         /*    those you create) have to be            */
  2322.                                                                                         /*    redrawn separately in response to    */
  2323.                                                                                         /*    a doRefresh event, so it's a good    */
  2324.                                                                                         /*    idea to keep them in a separate        */
  2325.                                                                                         /*    routine.                                                    */
  2326.  
  2327.   EnableMenu(FileMenu, CloseItem, enabled);    /*Enable the File menu's Close                */
  2328.                                                                                       /*    command, now that there's a window*/
  2329.   }                                                                                    /*    to close.                                                    */
  2330.  
  2331.  
  2332.  
  2333.  
  2334. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  2335.  * C r e a t e   D e m o   W i n d o w   4 :
  2336.  *    This demo shows off several Tools Plus features:
  2337.  *        • Cursor animation (the wristwatch cursor spins)
  2338.  *        • Filtering unwanted events when the application is busy (all typing and mouse
  2339.  *          clicks are filtered, so your application only gets Command-. events when the
  2340.  *            user wants to halt a lengthy process).
  2341.  *        • Secondary event loop in an application
  2342.  *        • Background processing (an ongoing process that runs all the time)
  2343.  *        • Progress thermometer
  2344.  *
  2345.  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  2346. void OpenDemoWindow4 (void)
  2347.     {
  2348.     Rect                ThermometerRect;                            /*Pregress thermometer's location            */
  2349.     float                PercentComplete;                            /*Percentage complete (.5 = 50%)            */
  2350.   long                NextThermometerTime;                    /*Next thermometer update time (ticks)*/
  2351.   Boolean            Done;                                                    /*Is this demo done? (either Command-.*/
  2352.                                                                                       /*    by user or thermometer is at 100%)*/
  2353.  
  2354.  
  2355.   CursorShape(watchCursor);                                    /*Set the cursor to a wrist-watch            */
  2356.                                                                                         /*Open a window to tell the user about*/
  2357.                                                                                         /*    the lengthy process (automatically*/
  2358.                                                                                         /*    centered)…                                                */
  2359.   WindowOpen(DemoWindow4, 0, 0, 265, 100, "\p", dBoxProc + wCenter, NoGoAway, Modal);
  2360.   TextFont(systemFont);                                            /*The message is displayed in Chicago    */
  2361.   TextSize(12);                                                            /*    12pt.                                                            */
  2362.   DrawWindow4Contents();                                        /*Draw this window's message                    */
  2363.  
  2364.   SetRect(&ThermometerRect, 15, 42, 250, 55);/*Define thermometer's co-ordinates    */
  2365.   PercentComplete = 0;                                            /*Initialize thermometer's value (0%)    */
  2366.   NextThermometerTime = 0;                                    /*Force thermometer update right away    */
  2367.   Done = false;                                                            /*This demo is not completed yet            */
  2368.  
  2369.                                                                                         /* L o c a l   E v e n t   L o o p        */
  2370.   while (!Done) {                                                        /*Keep running until we're done…            */
  2371.         if (PollSystem(&Poll)) {                                /*If an event has been detected…            */
  2372.         switch (Poll.What)                                        /*Determine what kind of event has        */
  2373.                 {                                                                        /*    occurred…                                                    */
  2374.                 case doRefresh:                                         /*A window needs to be refreshed…            */
  2375.                     RefreshWindow();                                    /*    redraw the specified window.  A        */
  2376.                     break;                                                        /*    screen saver may cause this event,*/
  2377.                                                                                         /*    even in a modal window like this    */
  2378.                                                                                         /*    one.                                                            */
  2379.                 case doKeyDown:                                            /*If the user typed a character.  All    */
  2380.                     Done = true;                                            /*    characters other than Command-.        */
  2381.                     break;                                                        /*    are filtered out, so we know the    */
  2382.                                                                                         /*    user has typed Command-. to halt    */
  2383.                                                                                         /*    the process.                                            */
  2384.                 default:                                                        /*All other events are ignored by            */
  2385.                      break;                                                        /*    this demo.                                                */
  2386.               }                                                                        /*                                                                        */
  2387.             }                                                                            /* B a c k g r o u n d   processing…    */
  2388.         else if (TickCount() >= NextThermometerTime)    /*No event available, so if it    */
  2389.             {                                                                                        /*    is time to do the next            */
  2390.                                                                                                     /*    thermometer update…                    */
  2391.             NextThermometerTime = TickCount() + 10;            /*Next update will be in 10            */
  2392.                                                                                                     /*    ticks (6 times/second)            */
  2393.             PercentComplete = PercentComplete + 0.005;    /*Add 1/2% completion to the        */
  2394.                                                                                                     /*    thermometer,                                */
  2395.             DrawThermometer(&ThermometerRect, PercentComplete);    /*Update the thermometer*/
  2396.             if (PercentComplete >= 1)                            /*If the thermometer reads 100%…            */
  2397.                 Done = true;                                                /*    we're done with this demo window.    */
  2398.         }                                                                            /*                                                                        */
  2399.     }                                                                                /*                                                                        */
  2400.  
  2401.   CloseTheWindow(DemoWindow4);                            /*End this demo by closing its window    */
  2402.   ResetCursor();                                                        /*Get rid of the watch cursor, and set*/
  2403.                                                                                       /*    it according to its location and    */
  2404.     }                                                                                    /*    relation to active window.                */
  2405.  
  2406.  
  2407.  
  2408.  
  2409. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  2410.  * C r e a t e   D e m o   W i n d o w   5 :
  2411.  *    This demo shows how to write code that does color drawing that is dependent on
  2412.  *    the monitor's settings (ie: the number of colors, number of shades of gray, or
  2413.  *    black and white).  With very little additional effort, your application can
  2414.  *    also be made to be compatible with Macintoshes that have multiple-monitors.
  2415.  *
  2416.  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  2417. void OpenDemoWindow5 (void)
  2418.     {                                                                                    /*Open the window (it automatically        */
  2419.                                                                                         /*    shifts down to compensate for an    */
  2420.                                                                                         /*    open Tool Bar, and its position is*/
  2421.                                                                                         /*    "tiled")…                                                    */
  2422.   WindowOpen(DemoWindow5, 0, 0, 310, 208, "\pColor Drawing and Multiple Monitors", noGrowDocProc + wTile, GoAway, NotModal);
  2423.                                                                                         /*Create the "OK" push-button.  This    */
  2424.                                                                                         /*    is the window's default button,        */
  2425.                                                                                         /*    and it is selected automatically    */
  2426.                                                                                         /*    when you press Return or Enter…        */
  2427.   NewButton(OkButton, 125, 170, 185, 190, "\pOK", DefaultButton, enabled, notSelected);
  2428.  
  2429.  
  2430.   TextFont(geneva);                                                    /*All text is drawn in Geneva 9pt.        */
  2431.   TextSize(9);                                                            /*                                                                        */
  2432.   DrawWindow5Contents();                                        /*Draw the rest of the objects in this*/
  2433.                                                                                       /*    demo window.  All Tools Plus            */
  2434.                                                                                       /*    objects are auto matically updated*/
  2435.                                                                                       /*    when a window needs to be                    */
  2436.                                                                                       /*    refreshed, such as when you bring    */
  2437.                                                                                       /*    it to the front to make it active.*/
  2438.                                                                                         /*        Non-Tools Plus objects (ie:            */
  2439.                                                                                         /*    those you create) have to be            */
  2440.                                                                                         /*    redrawn separately in response to    */
  2441.                                                                                         /*    a doRefresh event, so it's a good    */
  2442.                                                                                         /*    idea to keep them in a separate        */
  2443.                                                                                         /*    routine.                                                    */
  2444.   EnableMenu(FileMenu, CloseItem, enabled);    /*Enable the File menu's Close                */
  2445.                                                                                       /*    command, now that there's a window*/
  2446.   }                                                                                    /*    to close.                                                    */
  2447.  
  2448.  
  2449.  
  2450.  
  2451. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  2452.  * C r e a t e   D e m o   W i n d o w   6 :
  2453.  *    This demo shows off Tools Plus's Dynamic Alerts.  Dynamic Alerts are self
  2454.  *    contained (you don't have to do anything other than call it and wait for the
  2455.  *    user to respond).  Breaking from tradition that was previously established by
  2456.  *    the "OpenDemoWindow…" routines, this demo does everything pertaining to
  2457.  *    displaying Dynamic Alerts, detecting user action, and responding to events.
  2458.  *
  2459.  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  2460. void OpenDemoWindow6 (void)
  2461.     {
  2462.     #define            ContinueAlert                 11500        /*Button definition for a "Continue"    */
  2463.                                                                                         /*    dynamic alert.                                        */
  2464.     #define            SilentContinueAlert    -11500        /*Button definition for a "Continue"    */
  2465.                                                                                         /*    dynamic alert that doesn't beep        */
  2466.                                                                                         /*    the user.                                                    */
  2467.     #define            EndAlert                        -33987        /*Button definition using three                */
  2468.                                                                                         /*    custom buttons.                                        */
  2469.  
  2470.     char                Msg[256];                                            /*Long message displayed in a dynamic    */
  2471.                                                                                         /*    alert box (too long to include as    */
  2472.                                                                                         /*    a single line of source code).        */
  2473.                                                                                         /*    Note that this is a C string!            */
  2474.  
  2475.  
  2476.                                                                                         /*The message for the first alert is    */
  2477.                                                                                         /*    too long to include in a single        */
  2478.                                                                                         /*    line of source code, to we can        */
  2479.                                                                                         /*    assign a value to the Msg                    */
  2480.                                                                                         /*    variable…                                                    */
  2481.   strcpy(Msg, "This is an dynamic alert box.  Dynamic Alerts automatically adjust to accommodate the text your application provides them.  In fact, they’re smart enough to recognize “carriage returns” as “new line” commands.\r\rClick “Continue” for more examples.");
  2482.                                                                                         /*These first 2 alerts ignore which        */
  2483.                                                                                         /*    button that was clicked…                    */
  2484.      AlertBox(noteIcon, C2PStr(Msg), ContinueAlert);    /*                                                            */
  2485.   AlertBox(stopIcon, "\pIcons…\r\rYou can display any icon you want in a Dynamic alert, including color icons.\r\rAlertBox calls Tools Plus’s DrawIcon routine, so it’s smart enough to pick the right icon for your monitor’s settings.", SilentContinueAlert);
  2486.  
  2487.                                                                                         /*This alert displays 2 buttons: Yes    */
  2488.                                                                                         /*    and No.  If the user answers Yes,    */
  2489.                                                                                         /*    the demo continues…                                */
  2490.   if (YesAltBut == AlertBox(noteIcon, "\pDo you want to continue with more examples of Dynamic Alerts?", YesNoAlert))
  2491.         {                                                                                /*                                                                        */
  2492.     AlertBox(cautionIcon, "\pDynamic Alerts can even do unusual things, like alerts with no buttons (click in this window to get rid of it).", NoButtonAlert);
  2493.     AlertBox(ModemIcon, "\pSave modem preferences before quitting?\r(Just kidding!)", NoYesCanAlert);
  2494.     AlertButtonName(7, "\pYup!");                        /*This Dynamic Alert shows how you can*/
  2495.     AlertButtonName(8, "\pWow!");                        /*    rename buttons to customize your    */
  2496.     AlertButtonName(9, "\pGnarly");                    /*    application.  The available                */
  2497.                                                                                     /*    options make it seem like you            */
  2498.                                                                                     /*    have thousands of    customized            */
  2499.                                                                                     /*    alerts in your application.                */
  2500.         AlertBox(NoIcon, "\pSo, are you impressed with Dynamic Alerts?", EndAlert);/*    */
  2501.         }                                                                                /*                                                                        */
  2502.     }                                                                                    /*                                                                        */
  2503.  
  2504.  
  2505.  
  2506.  
  2507. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  2508.  * C r e a t e   D e m o   W i n d o w   7 :
  2509.  *  This demo demonstrates how easy it is to create and work with Pop-Up Menus.
  2510.  *    Tools Plus gives you features and options ordinary Pop-Up Menus don’t have.
  2511.  *    Also, Tools Plus's Pop-Up menu's work identically across all systems, unlike
  2512.  *    ordinary Mac Pop-Up Menus that provide some features that are exclusive to
  2513.  *    System 7.
  2514.  *
  2515.  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  2516. void OpenDemoWindow7 (void)
  2517.     {                                                                                    /*Open the window (it automatically        */
  2518.                                                                                         /*    shifts down to compensate for an    */
  2519.                                                                                         /*    open Tool Bar, and its position is*/
  2520.                                                                                         /*    "tiled")…                                                    */
  2521.   WindowOpen(DemoWindow7, 0, 0, 390, 296, "\pPop-Up Menus", noGrowDocProc + wTile, GoAway, NotModal);        
  2522.  
  2523.                                                                                         /* P o p - U p   M e n u s :    -    -    -    -    */
  2524.     /*    Example 1…                                                          Create a standard (default) Pop-Up    */
  2525.                                                                                         /*    Menu.  It is displayed in the            */
  2526.                                                                                         /*    System Font (Chicago 12pt) and        */
  2527.                                                                                         /*    only allows selection of one item    */
  2528.                                                                                         /*    at a time.                                                */
  2529.                                                                                         /*    NOTE: If you specify the bottom    */
  2530.                                                                                         /*    of the Pop- Up Menu's rectangle to*/
  2531.                                                                                         /*    be the same as the top, it is be    */
  2532.                                                                                         /*    created at exactly the font's            */
  2533.                                                                                         /*    height…                                                        */
  2534.   NewPopUp(popMenu1, 110, 20, 209, 20, "\pDay of Week:", popupDefaultType, enabled);
  2535.   PopUpMenu(popMenu1, 1, enabled, "\pSunday");        /*Populate the Pop-Up Menu with    */
  2536.   PopUpMenu(popMenu1, 2, enabled, "\pMonday");        /*    days of the week.  At this    */
  2537.   PopUpMenu(popMenu1, 3, enabled, "\pTuesday!•");    /*    point, no item is selected    */
  2538.   PopUpMenu(popMenu1, 4, enabled, "\pWednesday");    /*    yet.    Notice that the third    */
  2539.   PopUpMenu(popMenu1, 5, enabled, "\pThursday");    /*    item (Tuesday) ismarked with*/
  2540.   PopUpMenu(popMenu1, 6, enabled, "\pFriday");        /*    a bullet character (•).            */
  2541.   PopUpMenu(popMenu1, 7, enabled, "\pSaturday");    /*    Marking any item "selects"    */
  2542.                                                                                                   /*    it, and automatically                */
  2543.                                                                                                   /*    displays it in the menu's        */
  2544.                                                                                                   /*    content area.                                */
  2545.  
  2546.  
  2547.     /*    Example 2…                                                          Create a second Pop-Up Menu.  This    */
  2548.                                                                                         /*    one shows the selected item's    icon*/
  2549.                                                                                         /*    and hides the "down arrow".                */
  2550.   NewPopUp(popMenu2, 110, 70, 216, 70, "\pSearch Here:", popupIconTitle + popupNoArrow, enabled);
  2551.   PopUpMenu(popMenu2, 1, enabled, "\pDesktop^44");        /*Populate the Pop-Up menu    */
  2552.   PopUpMenu(popMenu2, 2, enabled, "\pHard Disk^45");    /*    with a simulated path        */
  2553.   PopUpMenu(popMenu2, 3, enabled, "\pTools Plus^46");    /*    starting from the                */
  2554.   PopUpMenu(popMenu2, 4, enabled, "\pTHINK C^47");        /*    Desktop to folders.    Each*/
  2555.   PopUpMenu(popMenu2, 5, enabled, "\pLibraries^47");    /*    menu item has an                */
  2556.   PopUpMenu(popMenu2, 6, enabled, "\p#Includes^47");    /*    associated icon (its        */
  2557.                                                                                                             /*    specifier follows the        */
  2558.                                                                                         /*    "^" symbol.)  Notethat the Menu        */
  2559.                                                                                         /*    Manager automatically adds 256 to    */
  2560.                                                                                         /*    the specifier to calculate the        */
  2561.                                                                                         /*    icon'sID.                                                    */
  2562.                                                                                         /*    Example:  ^44+256=300 'cicn' ID        */
  2563.   CheckPopUp(popMenu2, 1, on);                            /*Select the first item by placing a    */
  2564.                                                                                         /*    check mark beside it.                            */
  2565.  
  2566.  
  2567.     /*    Example 3…                                                        Create a third Pop-Up Menu that shows    */
  2568.                                                                                         /*    off how easily you can create            */
  2569.                                                                                         /*    picture menus.  This one uses two    */
  2570.                                                                                         /*    icons and no text.                                */
  2571.   NewPopUp(popMenu3, 110, 120, 170, 154, "\pSerial Port:", popupIconTitle + popupNoArrow, enabled);
  2572.   PopUpMenu(popMenu3, 1, enabled, "\p^48");    /*Populate the Pop-Up menu with the        */
  2573.   PopUpMenu(popMenu3, 2, enabled, "\p^49");    /*    Printer and Modem icons.                    */
  2574.   CheckPopUp(popMenu3, 1, on);                            /*Select the first item by placing a    */
  2575.                                                                                         /*    check mark beside it.                            */
  2576.  
  2577.  
  2578.     /*    Example 4…                                                        Create a fourth Pop-Up Menu that is a    */
  2579.                                                                                         /*    special type of control.  This one*/
  2580.                                                                                         /*    has a fixed title, and is used        */
  2581.                                                                                         /*    like an on-window pull-down menu.    */
  2582.   NewPopUp(popMenu4, 110, 190, 216, 190, "\pFormat", popupFixedTitle, enabled);
  2583.   PopUpMenu(popMenu4, 1, enabled, "\pClear");            /*Populate the menu with the        */
  2584.   PopUpMenu(popMenu4, 2, enabled, "\pParagraph…");/*    selections that can be made.*/
  2585.   PopUpMenu(popMenu4, 3, enabled, "\pCharacter…");/*    Even though you can put            */
  2586.   PopUpMenu(popMenu4, 4, enabled, "\pStyle…");        /*    check marks or other symbols*/
  2587.                                                                                                   /*    beside these items, this        */
  2588.                                                                                       /*    demo makes them perform an action    */
  2589.                                                                                         /*    just like pull-down menus.                */
  2590.  
  2591.  
  2592.     /*    Example 5…                                                        Mini Pop-Up Menu…                                            */
  2593.   TextFont(geneva);                                                    /*Set the window's font to Geneva 9pt.*/
  2594.   TextSize(9);                                                            /*    The pop-up menu will use these        */
  2595.                                                                                       /*    settings.                                                    */
  2596.                                                                                         /*Create the last menu using a                */
  2597.                                                                                         /*    different (non- System) font. This*/
  2598.                                                                                         /*    feature is available on     all            */
  2599.                                                                                         /*    systems (unlike ordinary pop-up        */
  2600.                                                                                         /*    menus). Never dim the menu's title*/
  2601.                                                                                         /*    or the selected item because            */
  2602.                                                                                         /*    Geneva 9pt is unreadable when its    */
  2603.                                                                                         /*    dithered on a 1-bit monitor (black*/
  2604.                                                                                         /*    and white) monitor…                                */
  2605.   NewPopUp(popMenu5, 110, 240, 143, 240, "\pSize:", popupUseWFont + popupNoArrow + popupNeverDimTitle + popupNeverDimSelection, enabled);
  2606.   PopUpMenu(popMenu5, 1, enabled, "\p9");        /*Populate the menu with a fictitious    */
  2607.   PopUpMenu(popMenu5, 2, enabled, "\p10");    /*    set of available font sizes.  Once*/
  2608.   PopUpMenu(popMenu5, 3, enabled, "\p12!•");/*    the menu is created, you can            */
  2609.   PopUpMenu(popMenu5, 4, enabled, "\p14");    /*    change the window's font and size    */
  2610.   PopUpMenu(popMenu5, 5, enabled, "\p18");    /*    without affecting the pop-up            */
  2611.   PopUpMenu(popMenu5, 6, enabled, "\p24");    /*    menus.                                                        */
  2612.   PopUpMenu(popMenu5, 7, enabled, "\p36");    /*    The third item (12pt) is marked        */
  2613.                                                                                       /*    with a bullet (•) to select that    */
  2614.                                                                                       /*    item.                                                            */
  2615.  
  2616.   DrawWindow7Contents();                                        /*Draw the rest of the objects in    this*/
  2617.                                                                                       /*    demo window.  All Tools Plus            */
  2618.                                                                                       /*    objects are auto matically updated*/
  2619.                                                                                       /*    when a window needs to be                    */
  2620.                                                                                       /*    refreshed, such as when you bring    */
  2621.                                                                                       /*    it to the front to make it active.*/
  2622.                                                                                         /*        Non-Tools Plus objects (ie:            */
  2623.                                                                                         /*    those you create) have to be            */
  2624.                                                                                         /*    redrawn separately in response to    */
  2625.                                                                                         /*    a doRefresh event, so it's a good    */
  2626.                                                                                         /*    idea to keep them in a separate        */
  2627.                                                                                         /*    routine.                                                    */
  2628.   EnableMenu(FileMenu, CloseItem, enabled);    /*Enable the File menu's Close                */
  2629.                                                                                       /*    command, now that there's a window*/
  2630.   }                                                                                    /*    to close.                                                    */
  2631.  
  2632.  
  2633.  
  2634.  
  2635. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  2636.  * C r e a t e   D e m o   W i n d o w   8 :
  2637.  *    This demo shows off Tools Plus's Picture Buttons.  A variety of buttons have
  2638.  *    been created to give you a taste of their abilities.  The top of this window
  2639.  *    includes a "window tool bar", a tool bar that is associated with a specific
  2640.  *    window, such as the kind seen in popular word processors.
  2641.  *      Picture Buttons are more versatile than most custom controls because you
  2642.  *    design their appearance and their behavior.  It's almost like having a button-
  2643.  *    building kit at your disposal.
  2644.  *
  2645.  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  2646. void OpenDemoWindow8 (void)
  2647.     {                                                                                    /*Define constants for the various        */
  2648.                                                                                         /*    bahavior and appearance                        */
  2649.                                                                                         /*    specifications…                                        */
  2650.                                                                                         /*Big 3D toolbar buttons stay down        */
  2651.                                                                                         /*    when selected, lightened when            */
  2652.                                                                                         /*    selected, and get whited out when    */
  2653.                                                                                         /*    disabled…                                                    */
  2654.     #define            BigToolBarSpec            picbutLockSelected + picbutBigSICN3D + picbutSelectLightenSICN3D + picbutDimUsingWhite
  2655.                                                                                         /*Small 3D toolbar buttons pop back up*/
  2656.                                                                                         /*    after being selected, lightened        */
  2657.                                                                                         /*    when selected, and get whited out    */
  2658.                                                                                         /*    when disabled…                                        */
  2659.     #define            SmallToolBarSpec        picbutSelectLightenSICN3D + picbutDimUsingWhite
  2660.                                                                                         /*The Plus/Minus button pair produce    */
  2661.                                                                                         /*    repeated doPictButton events while*/
  2662.                                                                                         /*    they are held down, have an                */
  2663.                                                                                         /*    alternate image when selected, and*/
  2664.                                                                                         /*    don't look different when                    */
  2665.                                                                                         /*    disabled…                                                    */
  2666.     #define            PlusMinusSpec                picbutRepeatEvents + picbutSelectAltImage + picbutDimNoChange
  2667.                                                                                         /*The ordinary icons (printer and            */
  2668.                                                                                         /*    modem) are selected when the            */
  2669.                                                                                         /*    mouse-down occurs, stay down when    */
  2670.                                                                                         /*    (selected, darken when selected.    */
  2671.                                                                                         /*    When disabled, use a white screen    */
  2672.                                                                                         /*    effect and preserve the border…        */
  2673.     #define            OrdinaryIconSpec        picbutInstantEvent + picbutLockSelected + picbutSelectDarken + picbutDimUsingWhite + picbutDimLeaveBorder
  2674.                                                                                         /*These tapedeck control buttons are    */
  2675.                                                                                         /*    selected when the mouse-down            */
  2676.                                                                                         /*    occurs, stay down when selected        */
  2677.                                                                                         /*    and use an alternate icon. They        */
  2678.                                                                                         /*    look the same disabled…                        */
  2679.     #define            TapedeckLockSpec    picbutInstantEvent + picbutLockSelected + picbutSelectAltImage + picbutDimNoChange
  2680.                                                                                         /*These tape deck controls to not lock*/
  2681.                                                                                         /*    down, and they look the same            */
  2682.                                                                                         /*    disabled…                                                    */
  2683.     #define            TapedeckSpec            picbutSelectAltImage + picbutDimNoChange    /*            */
  2684.  
  2685.  
  2686.                                                                                         /*Open the window (it automatically        */
  2687.                                                                                         /*    shifts down to compensate for an    */
  2688.                                                                                         /*    open Tool Bar, and its position is*/
  2689.                                                                                         /*    "tiled")…                                                    */
  2690.   WindowOpen(DemoWindow8, 0, 0, 472, 315, "\pPicture Buttons", noGrowDocProc + wTile, GoAway, NotModal);    
  2691.   ToolBarValue = 100;                                                /*Initialize the tool bar's value            */
  2692.  
  2693.   DrawWindow8Contents();                                        /*Draw all the objects in this demo        */
  2694.                                                                                       /*    window except for the buttons.        */
  2695.                                                                                       /*    This is done first to create a        */
  2696.                                                                                       /*    toolbar on which some buttons can    */
  2697.                                                                                       /*    be placed.  All Tools Plus objects*/
  2698.                                                                                       /*    are automatically updated when a    */
  2699.                                                                                       /*    window needs to be refreshed, such*/
  2700.                                                                                       /*    as when you bring it to the front    */
  2701.                                                                                       /*    to make it active.                                */
  2702.                                                                                       /*        Non-Tools Plus objects (ie:            */
  2703.                                                                                       /*    those you create) have to be            */
  2704.                                                                                       /*    redrawn separately in response to    */
  2705.                                                                                       /*    a doRefresh event, so it's a good    */
  2706.                                                                                       /*    idea to keep them in a separate        */
  2707.                                                                                       /*    routine.                                                    */
  2708.  
  2709.                                                                                         /*Create a pop-up menu in the title        */
  2710.                                                                                         /*    bar menu using the window's font    */
  2711.                                                                                         /*    (Geneva 9)…                                                */
  2712.     if (HasColorQuickDraw())                                    /*If Color Quickdraw is available…        */
  2713.         RGBForeColor(&ToolBarGray);                            /*    set foreground color to match the    */
  2714.                                                                                         /*    toolbar. The Pop-Up Menu picks        */
  2715.                                                                                         /*    this up to remember which color is*/
  2716.                                                                                         /*    behind the Pop-Up Menu.                        */
  2717.   NewPopUp(popMenu1, 9, 7, 68, 7, "\p", popupUseWFont + popupNoArrow + popupNeverDimOutline + popupNeverDimSelection, enabled);
  2718.   PenColorNormal();                                                    /*Restore to default colors                        */
  2719.   PopUpMenu(popMenu1, 1, enabled, "\pNormal!√");    /*Populate the pop-up menu with    */
  2720.   PopUpMenu(popMenu1, 2, disabled, "\p-");                /*    some items.    Demo 7 gives you*/
  2721.   PopUpMenu(popMenu1, 3, enabled, "\pPromote");        /*    details about how pop-up        */
  2722.   PopUpMenu(popMenu1, 4, enabled, "\pDemote");        /*    menus are created.                    */
  2723.   PopUpMenu(popMenu1, 5, enabled, "\pLateral");        /*                                                            */
  2724.  
  2725.                                                                                         /*Create a pop-up menu to control the    */
  2726.                                                                                         /*     "globe" button's "acceleration        */
  2727.                                                                                         /*    curve"…                                                        */
  2728.   NewPopUp(ButtonSpeedMenu, 406, 219, 460, 219, "\pΔRate:", popupUseWFont + popupNoArrow, enabled);    
  2729.   PopUpMenu(ButtonSpeedMenu, 1, enabled, "\pLinear");    /*Populate the pop-up menu    */
  2730.   PopUpMenu(ButtonSpeedMenu, 2, enabled, "\pSlow");        /*    with the choices…                */
  2731.   PopUpMenu(ButtonSpeedMenu, 3, enabled, "\pMedium!√");/*                                                    */
  2732.   PopUpMenu(ButtonSpeedMenu, 4, enabled, "\pFast");        /*                                                    */
  2733.  
  2734.  
  2735.  
  2736.                                                                                         /*C r e a t e   a l l   p i c t u r e    */
  2737.                                                                                         /*    b u t t o n s …                                        */
  2738.   NewPictButton(LeftArrowButton, 103, 3, LeftArrowIcon, picbutSelectAltImage + picbutDimNoChange, enabled, notSelected, 0, 0, 0);
  2739.   NewPictButton(RightArrowButton, 126, 3, RightArrowIcon, picbutSelectAltImage + picbutDimNoChange, enabled, notSelected, 0, 0, 0);
  2740.  
  2741.   NewPictButton(LeftAlignButton, 172, 3, LeftAlignIcon, BigToolBarSpec, enabled, notSelected, 0, 0, 0);
  2742.   NewPictButton(CenterAlignButton, 195, 3, CenterAlignIcon, BigToolBarSpec, enabled, notSelected, 0, 0, 0);
  2743.   NewPictButton(RightAlignButton, 218, 3, RightAlignIcon, BigToolBarSpec, enabled, notSelected, 0, 0, 0);
  2744.   NewPictButton(JustifyButton, 241, 3, JustifyIcon, BigToolBarSpec, enabled, notSelected, 0, 0, 0);
  2745.   
  2746.   NewPictButton(CutButton, 288, 4, CutIcon, SmallToolBarSpec, enabled, notSelected, 0, 0, 0);
  2747.   NewPictButton(BucketButton, 311, 4, BucketIcon, SmallToolBarSpec, enabled, notSelected, 0, 0, 0);
  2748.   NewPictButton(ClipboardButton, 334, 4, ClipboardIcon, SmallToolBarSpec, enabled, notSelected, 0, 0, 0);
  2749.  
  2750.   NewPictButton(PlusButton, 441, 5, PlusIcon, PlusMinusSpec, enabled, notSelected, 0, 0, 0);
  2751.   NewPictButton(MinusButton, 441, 15, MinusIcon, PlusMinusSpec, enabled, notSelected, 0, 0, 0);
  2752.   SetPictButtonSpeed(PlusButton, 2);                /*Set the button speed to 2 steps per    */
  2753.   SetPictButtonSpeed(MinusButton, 2);                /*    second for these two buttons.            */
  2754.  
  2755.   NewPictButton(PrinterButton, 28, 153, PrinterIcon, OrdinaryIconSpec, enabled, selected, 0, 0, 0);
  2756.   NewPictButton(ModemButton, 69, 153, ModemIcon, OrdinaryIconSpec, enabled, notSelected, 0, 0, 0);
  2757.  
  2758.     /*    This stepping button has nine icon images in its SICN resource.  The                */
  2759.     /*    button's value changes automatically with the top 1/2 of the button                    */
  2760.     /*    incrementing the value and the bottom 1/2 decrementing it (one step each        */
  2761.     /*    time the button is clicked). This is a BID 3D button that looks "pushed"        */
  2762.     /*    when selected (not darker or ligher)…                                                                                */
  2763.   NewPictButton(SteppingButton, 147, 161, ScrollingIcon, picbutAutoValueChg + picbutTopBottomSplit + picbutBigSICN3D + picbutSelectPushedSICN3D, enabled, notSelected, 1, 3, 9);
  2764.  
  2765.     /*    This scrolling button has nine icon images in its SICN resource.  It keeps    */
  2766.     /*    producing doPictButton events while the mouse is held down.  The button's        */
  2767.     /*    value changes automatically with the top 1/2 of the button incrementing the    */
  2768.     /*    value and the bottom 1/2 decrementing it.  This is a BID 3D button that            */
  2769.     /*    looks "pushed" when selected (not darker or ligher)…                                                */
  2770.   NewPictButton(ScrollingButton, 170, 161, ScrollingIcon, picbutRepeatEvents + picbutAutoValueChg + picbutTopBottomSplit + picbutBigSICN3D + picbutSelectPushedSICN3D, enabled, notSelected, 1, 5, 9);
  2771.  
  2772.     /*    This is just about the most complicated button you can create.  It keeps        */
  2773.     /*    producing doPictButton events while the mouse is held down.  The button's        */
  2774.     /*    value changes automatically with the right 1/2 of the button incrementing        */
  2775.     /*    the value and the left decrementing it.  The rate of change accelerates (at    */
  2776.     /*    a medium rate) over time, and the button's values "wrap" (maximum + 1 =            */
  2777.     /*    start at minimum).  An alternate icon is used when the button is selected.    */
  2778.     /*    A white screen is applied to this icon when the button is disabled.                    */
  2779.   NewPictButton(GlobeButton, 410, 153, GlobeIcon, picbutRepeatEvents + picbutAutoValueChg + picbutScaleMedAccel + picbutValueWrap + picbutLeftRightSplit + picbutSelectAltImage + picbutDimUsingWhite, enabled, notSelected, -179, 0, 180);
  2780.  
  2781.                                                                                         /*Tapedeck buttons always have 1            */
  2782.                                                                                         /*    selected…                                                    */
  2783.   NewPictButton(RewindButton, 17, 235, RewindIcon, TapedeckLockSpec, enabled, notSelected, 0, 0, 0);
  2784.   NewPictButton(StopButton, 48, 235, StopTapeIcon, TapedeckSpec, enabled, notSelected, 0, 0, 0);
  2785.   NewPictButton(FastFwdButton, 79, 235, FastFwdIcon, TapedeckLockSpec, enabled, notSelected, 0, 0, 0);
  2786.   NewPictButton(PauseButton, 17, 255, PauseIcon, TapedeckSpec, enabled, notSelected, 0, 0, 0);
  2787.   NewPictButton(RecordButton, 48, 255, RecordIcon, TapedeckSpec, enabled, notSelected, 0, 0, 0);
  2788.   NewPictButton(PlayButton, 79, 255, PlayIcon, TapedeckLockSpec, enabled, notSelected, 0, 0, 0);
  2789.  
  2790.     /*    This is a dual state button (Power-On, Power-Off), so it is considered to        */
  2791.     /*    be a "Multi-Stage" button (Off=0, 1=On). The button's value changes                    */
  2792.     /*    automatically when selected by the user.  The values "wrap" to allow 1 (on)    */
  2793.     /*    to start back at 0 (off) again.  An alternate icon is used to depict the        */
  2794.     /*    selected button (down position), and disabled button for maximum visual            */
  2795.     /*    control…                                                                                                                                        */
  2796.   NewPictButton(PowerButton, 173, 235, PowerIcon, picbutMultiStage + picbutAutoValueChg + picbutValueWrap + picbutSelectAltImage + picbutDimAltImage, enabled, notSelected, 0, 0, 1);
  2797.  
  2798.  
  2799.     /*    This is a dual state button that uses a set of PICTs. Like the button above,*/
  2800.     /*    it is Multi-State (left=0, right=1) and its value changes automatically when*/
  2801.     /*    selected by the user.  This button uses different PICTs for the selected        */
  2802.     /*    state, and for the screen depth (8-bit, 4-bit, and B&W). It also uses a            */
  2803.     /*    mask, even though it is not necessary on a white background.                                */
  2804.   NewPictButton(FlipButton, 163, 277, FlipSwitchPICT, picbutAutoValueChg + picbutLeftRightSplit + picbutMultiStage + picbutUsePICTS + picbutGray4use8 + picbutSelectAltImage + picbutDimNoChange, enabled, notSelected, 0, 0, 1);
  2805.  
  2806.                                                                                         /*This is a really simple push-button    */
  2807.                                                                                         /*    that uses an alternate icon when    */
  2808.                                                                                         /*    the button is selected. When            */
  2809.                                                                                         /*    disabled, a white screen is                */
  2810.                                                                                         /*    overlayed and the border is                */
  2811.                                                                                         /*    preserved…                                                */
  2812.   NewPictButton(DoneButton, 392, 280, DoneIcon, picbutSelectAltImage + picbutDimUsingWhite + picbutDimLeaveBorder, enabled, notSelected, 0, 0, 0);
  2813.  
  2814.   EnableMenu(FileMenu, CloseItem, enabled);    /*Enable the File menu's Close                */
  2815.                                                                                       /*    command, now that there's a window*/
  2816.   }                                                                                    /*    to close.                                                    */
  2817.  
  2818.  
  2819.  
  2820.  
  2821. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  2822.  * C r e a t e   D e m o   W i n d o w   9 :
  2823.  *    In Tools Plus, creating a Tool Bar is as easy as opening a window.  Tools Plus
  2824.  *    makes sure the Tools Bar is always at the front, and always active.  This Tool
  2825.  *    Bar contains a Pop-Up Menu and several Picture Buttons (they are simply a
  2826.  *    duplicate of the "window tool bar" seen in demo 8.
  2827.  *        Tools Plus automatically hides the Tool Bar when your application is
  2828.  *    suspended, and displays it again when your application resumes (when running
  2829.  *    under MultiFinder™ or System 7).
  2830.  *        This routine is used to both open and close the application's Tool Bar.  Note
  2831.  *    that all open windows can optionally be shifted down when a Tool Bar is opened
  2832.  *    to make sure that no windows are hidden behind the Tool Bar.  You can also tell
  2833.  *    Tools Plus to offset future windows downward to account for the Tool Bar's space
  2834.  *    on the monitor.
  2835.  *
  2836.  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  2837. void OpenDemoWindow9 (void)
  2838.     {                                                                                    /*These constants describe the behavior    */
  2839.                                                                                         /*    and look of picture buttons in the    */
  2840.                                                                                         /*    Tool Bar. Demo 8 provides more            */
  2841.                                                                                         /*    detail about picture buttons. All        */
  2842.                                                                                         /*    the buttons here have been                    */
  2843.                                                                                         /*    duplicated from Demo 8…                            */
  2844.     #define            BigToolBarSpec            picbutLockSelected + picbutBigSICN3D + picbutSelectLightenSICN3D + picbutDimUsingWhite
  2845.     #define            SmallToolBarSpec        picbutSelectLightenSICN3D + picbutDimUsingWhite
  2846.  
  2847.  
  2848.                                                                                         /* O p e n   T o o l   B a r …                    */
  2849.     if (!WindowIsOpen(ToolBarWindow))                    /*If the Tool Bar is not open…                    */
  2850.         {                                                                                /*                                                                            */
  2851.                                                                                         /*Open a Tool Bar that is 26 pixels            */
  2852.                                                                                         /*    high.  Shift all open windows down    */
  2853.                                                                                         /*    as the Tool Bar opens, and as future*/
  2854.                                                                                         /*    windows are opened, offset them            */
  2855.                                                                                         /*    downward to compensate for the open    */
  2856.                                                                                         /*    Tool Bar…                                                        */
  2857.         ToolBarOpen(ToolBarWindow, 26, tbShiftWindows + tbOffsetNewWindows);    /*                */
  2858.  
  2859.     RenameItem(DemosMenu, 10, "\pHide Tool Bar");    /*Rename the menu item                        */
  2860.  
  2861.     DrawWindow9Contents();                                    /*Paint the Tool Bar gray.  Picture            */
  2862.                                                                                         /*    buttons will be placed on top of the*/
  2863.                                                                                         /*    gray.  All Tools Plus objects are        */
  2864.                                                                                         /*    automatically updated when a window    */
  2865.                                                                                         /*    needs to be refreshed.                            */
  2866.                                                                                         /*        Non-Tools Plus objects (ie: those    */
  2867.                                                                                         /*    you create) have to be redrawn            */
  2868.                                                                                         /*    separately in response to a                    */
  2869.                                                                                         /*    doRefresh event, so it's a good idea*/
  2870.                                                                                         /*    to keep them in a separate routine.    */
  2871.         if (HasColorQuickDraw())                                /*If Color Quickdraw is available…            */
  2872.             RGBForeColor(&ToolBarGray);                        /*    set foreground color to match the        */
  2873.                                                                                         /*    toolbar. The Pop-Up Menu picks this    */
  2874.                                                                                         /*    up to remember which color is behind*/
  2875.                                                                                         /*    the Pop-Up Menu.                                        */
  2876.         TextFont(geneva);                                                /*The pop-up menu will use Geneva 9pt        */
  2877.     TextSize(9);                                                        /*                                                                            */
  2878.                                                                                         /*Create the pop-up menu…                                */
  2879.     NewPopUp(popMenu1, 9, 7, 68, 7, "\p", popupUseWFont + popupNoArrow + popupNeverDimOutline + popupNeverDimSelection, enabled);
  2880.     PenColorNormal();                                                /*Restore to default colors                            */
  2881.     PopUpMenu(popMenu1, 1, enabled, "\pNormal!√");    /*Populate the pop-up menu with    */
  2882.     PopUpMenu(popMenu1, 2, enabled, "\pSection");        /*    some items.    Demo 7 gives you*/
  2883.     PopUpMenu(popMenu1, 3, enabled, "\pBullet");        /*    details about how pop-up        */
  2884.     PopUpMenu(popMenu1, 4, enabled, "\pTable");            /*    menus are created.                    */
  2885.  
  2886.                                                                                         /*C r e a t e   a l l   p i c t u r e        */
  2887.                                                                                         /*    b u t t o n s …                                            */
  2888.                                                                                         /*These are the same picture buttons you*/
  2889.                                                                                         /*    saw described in detail in Demo 8…    */
  2890.         NewPictButton(LeftArrowButton, 103, 2, LeftArrowIcon, picbutSelectAltImage + picbutDimNoChange, enabled, notSelected, 0, 0, 0);
  2891.     NewPictButton(RightArrowButton, 126, 2, RightArrowIcon, picbutSelectAltImage + picbutDimNoChange, enabled, notSelected, 0, 0, 0);
  2892.     NewPictButton(LeftAlignButton, 172, 2, LeftAlignIcon, BigToolBarSpec, enabled, notSelected, 0, 0, 0);
  2893.     NewPictButton(CenterAlignButton, 195, 2, CenterAlignIcon, BigToolBarSpec, enabled, notSelected, 0, 0, 0);
  2894.     NewPictButton(RightAlignButton, 218, 2, RightAlignIcon, BigToolBarSpec, enabled, notSelected, 0, 0, 0);
  2895.     NewPictButton(JustifyButton, 241, 2, JustifyIcon, BigToolBarSpec, enabled, notSelected, 0, 0, 0);
  2896.     NewPictButton(CutButton, 288, 3, CutIcon, SmallToolBarSpec, enabled, notSelected, 0, 0, 0);
  2897.     NewPictButton(BucketButton, 311, 3, BucketIcon, SmallToolBarSpec, enabled, notSelected, 0, 0, 0);
  2898.     NewPictButton(ClipboardButton, 334, 3, ClipboardIcon, SmallToolBarSpec, enabled, notSelected, 0, 0, 0);
  2899.         }
  2900.  
  2901.  
  2902.   else    {                                                                        /* C l o s e   T o o l   B a r …                */
  2903.     WindowClose(ToolBarWindow);                            /*Close the Tool Bar's window (all open    */
  2904.                                                                                         /*    windows automatically move up.            */
  2905.     RenameItem(DemosMenu, 10, "\pShow Tool Bar");    /*Rename the menu item                        */
  2906.        }
  2907.     }
  2908.  
  2909.  
  2910.  
  2911.  
  2912. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  2913.  * C r e a t e   D e m o   W i n d o w   10 :
  2914.  *    In Tools Plus, creating a floating palette (windoid) is as easy as opening a
  2915.  *    window.  Tools Plus makes sure the palette if opened behind the Tool Bar (if
  2916.  *    there is one) and in front of standard windows (if there are any).  Palettes
  2917.  *    are always active.
  2918.  *        Tools Plus automatically hides palettes when your application is suspended,
  2919.  *    and displays them when your application resumes (when running under MultiFinder™
  2920.  *    or System 7).
  2921.  *
  2922.  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  2923. void OpenDemoWindow10 (void)
  2924.     {                                                                                    /*All picture buttons on this floating    */
  2925.                                                                                         /*    palette are small SICN 3D icons            */
  2926.                                                                                         /*    (colorized by Tools Plus).  They        */
  2927.                                                                                         /*    respond instantly when clicked…            */
  2928.     #define            SmallButtonSpec        picbutInstantEvent + picbutSelectDarkenSICN3D
  2929.  
  2930.     short                theButton;                                        /*Button number counter                                    */
  2931.     short                theIcon;                                            /*Icon number counter                                        */
  2932.     Point                thePoint;                                            /*Top left corner for button                        */
  2933.  
  2934.                                                                                         /* O p e n   V e r t i c a l                        */
  2935.                                                                                         /*        P a l e t t e …                                        */
  2936.                                                                                         /*Open the floating palette (it                    */
  2937.                                                                                         /*    automatically shifts down to                */
  2938.                                                                                         /*    compensate for an open Tool Bar)…        */
  2939.   WindowOpen(VerticalPalette, 450, 40, 495, 229, "\p", paletteProc, GoAway, NotModal);
  2940.  
  2941.                                                                                         /*C r e a t e   a l l   p i c t u r e        */
  2942.                                                                                         /*    b u t t o n s …                                            */
  2943.                                                                                         /*Use some basic math to create the            */
  2944.                                                                                         /*    picture buttons for this palette.        */
  2945.                                                                                         /*    All the picture buttons are buttons    */
  2946.                                                                                         /*    are sequentially numbered, and so is*/
  2947.                                                                                         /*    their placement on this palette.        */
  2948.   theIcon = FirstVPaletteIcon;                            /*Start with using the first icon in        */
  2949.                                                                                         /*    this palette.                                                */
  2950.                                                                                         /*Cycle through all buttons in palette…    */
  2951.   for (theButton = VPaletteMinButton; theButton <= VPaletteMaxButton; theButton++)
  2952.       {                                                                                /*                                                                            */
  2953.         thePoint.h = ((theButton -1) % 2) * 23 - 1;    /*Horizontally, odd numbered buttons*/
  2954.                                                                                                 /*    are at 0 and even numbered            */
  2955.                                                                                                 /*    buttons are at 23 pixels.                */
  2956.     thePoint.v = ((theButton - 1) / 2) * 19 - 1;/*Two buttons fit side-by side            */
  2957.                                                                                     /*    horizontally, so after each two            */
  2958.                                                                                     /*    buttons, shift down 19 pixels.            */
  2959.                                                                                         /*Create the picture button…                        */
  2960.         NewPictButton(theButton, thePoint.h, thePoint.v, theIcon, SmallButtonSpec, enabled, notSelected, 0, 0, 0);
  2961.     theIcon = theIcon + 1;                                    /*Increment the icon for the next                */
  2962.     }                                                                                /*    picture button.                                            */
  2963.     }
  2964.  
  2965.  
  2966.  
  2967.  
  2968. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  2969.  * C r e a t e   D e m o   W i n d o w   11 :
  2970.  *    In Tools Plus, creating a floating palette (windoid) is as easy as opening a
  2971.  *    window.  Tools Plus makes sure the palette if opened behind the Tool Bar (if
  2972.  *    there is one) and in front of standard windows (if there are any).  Palettes
  2973.  *    are always active.
  2974.  *        Tools Plus automatically hides palettes when your application is suspended,
  2975.  *    and displays them when your application resumes (when running under MultiFinder™
  2976.  *    or System 7).
  2977.  *
  2978.  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  2979. void OpenDemoWindow11 (void)
  2980.     {                                                                                    /*All picture buttons on this floating    */
  2981.                                                                                         /*    palette respond instantly when            */
  2982.                                                                                         /*    clicked.  The image darkens when        */
  2983.                                                                                         /*    selected, is dithered when disabled    */
  2984.                                                                                         /*    (with it border left unaffected)…        */
  2985.     #define            HPaletteButtonSpec    picbutInstantEvent + picbutSelectDarken + picbutDimUsingWhite + picbutDimLeaveBorder
  2986.  
  2987.     short                theButton;                                        /*Button number counter                                    */
  2988.     short                theIcon;                                            /*Icon number counter                                        */
  2989.     Point                thePoint;                                            /*Top left corner for button                        */
  2990.     short                ButtonsPerRow;                                /*Number of buttons per row on palette    */
  2991.     short                ButtonInRow;                                    /*Button number in current row (1 to x)    */
  2992.  
  2993.  
  2994.                                                                                         /* O p e n   H o r i z o n t a l                */
  2995.                                                                                         /*        P a l e t t e …                                        */
  2996.                                                                                         /*Open the floating palette (it                    */
  2997.                                                                                         /*    automatically shifts down to                */
  2998.                                                                                         /*    compensate for an open Tool Bar)…        */
  2999.     WindowOpen(HorizontalPalette, 239, 260, 508, 299, "\p", altPaletteProc, GoAway, NotModal);
  3000.  
  3001.                                                                                         /*C r e a t e   a l l   p i c t u r e        */
  3002.                                                                                         /*    b u t t o n s …                                            */
  3003.                                                                                         /*Use some basic math to create the            */
  3004.                                                                                         /*    picture buttons for this palette.        */
  3005.                                                                                         /*    All the picture buttons are buttons    */
  3006.                                                                                         /*    are sequentially numbered, and so is*/
  3007.                                                                                         /*    their placement on this palette.        */
  3008.                                                                                         /*    Double borders between groups of        */
  3009.                                                                                         /*    buttons are created by placing the    */
  3010.                                                                                         /*    buttons further apart.                            */
  3011.   theIcon = FirstHPaletteIcon;                            /*Start with using the first icon in        */
  3012.                                                                                       /*    this palette.                                                */
  3013.                                                                                       /*Cycle through all buttons in palette…    */
  3014.   for (theButton = HPaletteMinButton; theButton <= HPaletteMaxButton; theButton++)
  3015.       {                                                                                /*                                                                            */
  3016.                                                                                         /*Calc num. of picture buttons per row    */
  3017.                                                                                         /*    (with two rows on this palette)…        */
  3018.     ButtonsPerRow = (HPaletteMaxButton - HPaletteMinButton + 1) / 2;    /*                        */
  3019.     if (theButton <= ButtonsPerRow)                    /*Calculate the button's relative number*/
  3020.             ButtonInRow = theButton;                            /*    in this row (i.e. the first button    */
  3021.         else                                                                        /*    in this row, second, third, etc.)      */
  3022.             ButtonInRow = theButton - ButtonsPerRow;/*    This number is used to calculate    */
  3023.                                                                                         /*    horizontal button spacing.                    */
  3024.                                                                                         /*Horizontally, each button is 24 pixels*/
  3025.                                                                                         /*    apart from the previous one. There    */
  3026.                                                                                         /*    are borders at the end of the 4th,    */
  3027.                                                                                         /*    9th and 10th button, so add an extra*/
  3028.                                                                                         /*    2 pixels between those buttons…            */
  3029.     thePoint.h = (ButtonInRow - 1) * 24 + (2 * (ButtonInRow > 4)) + (2 * (ButtonInRow > 9)) + (2 * (ButtonInRow > 10)) - 1;
  3030.     thePoint.v = (theButton > ButtonsPerRow) * 20 - 1;    /*Half of the buttons fit on*/
  3031.                                                                                     /*    the top row, and the second half of    */
  3032.                                                                                     /*    them fit on the bottom row. The            */
  3033.                                                                                     /*    bottom row is 20 pixels lower than    */
  3034.                                                                                     /*    the first.                                                    */
  3035.                                                                                         /*Create the picture button…                        */
  3036.     NewPictButton(theButton, thePoint.h, thePoint.v, theIcon, HPaletteButtonSpec, enabled, notSelected, 0, 0, 0);
  3037.     theIcon = theIcon + 1;                                    /*Increment the icon for the next                */
  3038.     }                                                                                /*    picture button.                                            */
  3039.     }
  3040.  
  3041.  
  3042.  
  3043.  
  3044.  
  3045. /***********************************************************************************
  3046.  ***********************************************************************************
  3047.  *  R e s p o n s e s   t o   E v e n t s :
  3048.  *    The following routines are invoked in response to events that were detected in
  3049.  *    the main event loop.
  3050.  */
  3051.  
  3052.  
  3053.  
  3054. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  3055.  * R e f r e s h   A   W i n d o w :
  3056.  *    This routine is called in response to a "doRefresh" event.  It redraws the
  3057.  *    contents of a window.  Note that objects such as Scroll Bars, List Boxes,
  3058.  *    Buttons and Editing Fields are updated automatically.
  3059.  *        You should account for each of your application's windows in a routine such
  3060.  *    as this one, even if they are modal.  Modal windows may need updating if the Mac
  3061.  *    running your application is running a screen saver.  When the screen saver is
  3062.  *    woken up, chances are that it will demand that all windows be refreshed.
  3063.  *
  3064.  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  3065. void RefreshWindow (void)
  3066.     {
  3067.   CurrentWindow(Poll.Window);                                /*Make the affected window the current*/
  3068.                                                                                       /*    grafPort. That means that all            */
  3069.                                                                                       /*    drawing operations will be done        */
  3070.                                                                                       /*    on that window.                                        */
  3071.   BeginUpdate(WindowPointer(Poll.Window));    /*Restrict drawing to within the area    */
  3072.                                                                                       /*    that needs refreshing.  Any                */
  3073.                                                                                       /*    drawing done outside this area is    */
  3074.                                                                                       /*    ignored.                                                    */
  3075.   switch (Poll.Window)                                            /*Depending on which window needs to    */
  3076.       {                                                                                /*    be refreshed, call the appropriate*/
  3077.         case DemoWindow1:                                             /*    routine to do the required                */
  3078.         DrawWindow1Contents();                                /*    drawing…                                                    */
  3079.         break;                                                                /*                                                                        */
  3080.         case DemoWindow2:                                             /*                                                                        */
  3081.             DrawWindow2Contents();                                /*                                                                        */
  3082.         break;                                                                /*                                                                        */
  3083.         case DemoWindow3:                                             /*                                                                        */
  3084.             DrawWindow3Contents();                                /*                                                                        */
  3085.         break;                                                                /*                                                                        */
  3086.         case DemoWindow4:                                             /*                                                                        */
  3087.             DrawWindow4Contents();                                /*                                                                        */
  3088.         break;                                                                /*                                                                        */
  3089.         case DemoWindow5:                                             /*                                                                        */
  3090.             DrawWindow5Contents();                                /*                                                                        */
  3091.         break;                                                                /*                                                                        */
  3092.         case DemoWindow6:                                             /*                                                                        */
  3093.             DrawWindow6Contents();                                /*                                                                        */
  3094.         break;                                                                /*                                                                        */
  3095.         case DemoWindow7:                                             /*                                                                        */
  3096.             DrawWindow7Contents();                                /*                                                                        */
  3097.         break;                                                                /*                                                                        */
  3098.         case DemoWindow8:                                             /*                                                                        */
  3099.             DrawWindow8Contents();                                /*                                                                        */
  3100.         break;                                                                /*                                                                        */
  3101.     case ToolBarWindow:                                          /*                                                                        */
  3102.             DrawWindow9Contents();                                /*                                                                        */
  3103.         break;                                                                /*                                                                        */
  3104.         case VerticalPalette:                                     /*                                                                        */
  3105.             DrawWindow10Contents();                                /*                                                                        */
  3106.         break;                                                                /*                                                                        */
  3107.         case HorizontalPalette:                                 /*                                                                        */
  3108.             DrawWindow11Contents();                                /*                                                                        */
  3109.         break;                                                                /*                                                                        */
  3110.    }                                                                                /*                                                                        */
  3111.     EndUpdate(WindowPointer(Poll.Window));        /*End the update for the window, and    */
  3112.                                                                                         /*    tell the Mac you've finished            */
  3113.                                                                                         /*    updating this window (ie: clear        */
  3114.                                                                                         /*    the window's update region).            */
  3115.   CurrentWindowReset();                                            /*Reset the active window to also be    */
  3116.                                                                                       /*    the current window (all drawing        */
  3117.   }                                                                                    /*    will resume on the active window).*/
  3118.  
  3119.  
  3120.  
  3121.  
  3122. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  3123.  * U s e r   C l i c k e d   I n a c t i v e   W i n d o w :
  3124.  *    This routine is called in response to a "doChgWindow" event.  Note that
  3125.  *    clicking between the active window and a desk accessory, or between two desk
  3126.  *    accessories does not generate a doChgWindow event.     A doChgWindow event is
  3127.  *    generated only when the user tries to activate an inactive window belonging
  3128.  *    to your application.  In a full featured application, you may want to validate
  3129.  *    the active editing field and perform any other verifications before activating
  3130.  *    the window.
  3131.  *
  3132.  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  3133. void ChangeWindow (void)
  3134.     {
  3135.   ActivateWindow(Poll.Window);                            /*Activate the requested window                */
  3136.     }
  3137.  
  3138.  
  3139.  
  3140.  
  3141. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  3142.  * C h o o s e   A   M e n u :
  3143.  *    This routine is called in response to a "doMenu" event.  A doMenu event
  3144.  *    indicates that the user selected a menu or typed a Command-key equivalent for
  3145.  *    a menu.  Note that a doMenu event is not generated if a desk accessory's menu
  3146.  *    is selected.  The Edit menu's Undo, Cut, Copy, Paste, and Clear items
  3147.  *    automatically interact with the active editing field without you having to do
  3148.  *    anything.
  3149.  *
  3150.  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  3151. void MenuSelection (void)
  3152.     {
  3153.     switch (Poll.Menu.Num)
  3154.         {
  3155.         case ApplMenu:                                                    /* A p p l e  M e n u :    -    -    -    -    -    -    -    */
  3156.                                                                                         /*The only item in the Apple menu that*/
  3157.                                                                                         /*    generates an event is the "About…"*/
  3158.                                                                                         /*    item.  All we do is display a            */
  3159.                                                                                         /*    Dynamic Alert box…                                */
  3160.             AlertBox(NoIcon, "\pT o o l s   P l u s   D e m o   A p p l i c a t i o n\r\rWater’s Edge Software\rPO Box 70022\r2441 Lakeshore Road West\rOakville, Ontario\rCanada, L6L 6M9\r\r(416) 219-5628\r\r(Click this window to continue)", NoButtonAlert);
  3161.             break;                                                                /*                                                                        */
  3162.  
  3163.         case FileMenu:                                                     /* F i l e   M e n u :    -    -    -    -    -    -    -    */
  3164.             switch (Poll.Menu.Item)                                /*Determine the item selected within    */
  3165.                 {                                                                        /*    this menu…                                                */
  3166.                 case CloseItem:                                         /* Close…                                                            */
  3167.                  if (FirstStdWindowNumber() != 0)                    /*If standard window is open…    */
  3168.                         CloseTheWindow(FirstStdWindowNumber());    /*    close front std window.        */
  3169.                     else if (FirstPaletteNumber() != 0)                /*If flating palette is open…    */
  3170.                         CloseTheWindow(FirstPaletteNumber());        /*    close the front palette.    */
  3171.                     break;                                                                        /*                                                        */
  3172.                 case QuitItem:                                             /* Quit…                                                            */
  3173.                     ExitTheDemo = true;                                /*    set the "exit the demo" flag to        */
  3174.                     break;                                                        /*    true to indicate we're ready to        */
  3175.                 }                                                                        /*    return to the Finder.                            */
  3176.             break;                                                                /*                                                                        */
  3177.                 
  3178.         case DemosMenu:                                                    /* D e m o s   M e n u :    -    -    -    -    -    -    */
  3179.             {                                                                            /*When selecting an item from the            */
  3180.                                                                                         /*    Demos menu, it means "activate        */
  3181.                                                                                         /*    this demo window" if the window        */
  3182.                                                                                         /*    is already open, and "open this        */
  3183.                                                                                         /*    demo window" if it isn't open.        */
  3184.  
  3185.             if (Poll.Menu.Item == ToolBarItem)        /*If user selected the Hide/Show Tool */
  3186.                 OpenDemoWindow9();                                    /*    Bar item,    open or closes (hide)        */
  3187.             else                                                                    /*    the Tool Bar.                                            */
  3188.                 {                                                                        /*                                                                        */
  3189.  
  3190.  
  3191.                 ActivateWindow(Poll.Menu.Item);            /*Try to activate the window number        */
  3192.                                                                                         /*    that corresponds to the menu's        */
  3193.                                                                                         /*    item number. This will bring the    */
  3194.                                                                                         /*    window to the front.                            */
  3195.                 if (!WindowIsOpen(Poll.Menu.Item))    /*If the specified window is not open,*/
  3196.                     {                                                                    /*    it indicates the requested demo        */
  3197.                                                                                         /*    window is not open yet. So open        */
  3198.                                                                                         /*    the requested demo…                                */
  3199.                     switch (Poll.Menu.Item)                        /*Determine the item selected within    */
  3200.                         {                                                                /*    this menu    and open the specified    */
  3201.                         case 1:                                                 /*    demo window.                                            */
  3202.                             OpenDemoWindow1();                        /*                                                                        */
  3203.                             break;                                                /*                                                                        */
  3204.                         case 2:                                                 /*                                                                        */
  3205.                             OpenDemoWindow2();                        /*                                                                        */
  3206.                             break;                                                /*                                                                        */
  3207.                         case 3:                                                 /*                                                                        */
  3208.                             OpenDemoWindow3();                        /*                                                                        */
  3209.                             break;                                                /*                                                                        */
  3210.                         case 4:                                                 /*                                                                        */
  3211.                             OpenDemoWindow4();                        /*                                                                        */
  3212.                             break;                                                /*                                                                        */
  3213.                         case 5:                                                 /*                                                                        */
  3214.                             OpenDemoWindow5();                        /*                                                                        */
  3215.                             break;                                                /*                                                                        */
  3216.                         case 6:                                                 /*                                                                        */
  3217.                             OpenDemoWindow6();                        /*                                                                        */
  3218.                             break;                                                /*                                                                        */
  3219.                         case 7:                                                 /*                                                                        */
  3220.                             OpenDemoWindow7();                        /*                                                                        */
  3221.                             break;                                                /*                                                                        */
  3222.                         case 8:                                                 /*                                                                        */
  3223.                             OpenDemoWindow8();                        /*                                                                        */
  3224.                             break;                                                /*                                                                        */
  3225.                         }                                                             /*                                                                        */
  3226.                     }                                                                 /*                                                                        */
  3227.                 }                                                                     /*                                                                        */
  3228.             }                                                                         /*                                                                        */
  3229.             break;                                                                /*                                                                        */
  3230.  
  3231.         case PaletteDemoMenu:                                     /* P a l e t t e   D e m o s   M e n u*/
  3232.             {                                                                            /*The "Palettes" menu is hierarchic,    */
  3233.                                                                                         /*    so you treat it like a separate        */
  3234.                                                                                         /*    pull-down menu. When selecting an    */
  3235.                                                                                         /*    item from the Palettes Demos menu,*/
  3236.                                                                                         /*    it means "activate this palette        */
  3237.                                                                                         /*    window" if the window is already    */
  3238.                                                                                         /*    open, and "open this palette            */
  3239.                                                                                         /*    window" if it isn't open.                    */
  3240.             ActivateWindow(Poll.Menu.Item + VerticalPalette - 1);    /*Try to activate the    */
  3241.                                                                                         /*    palette number that corresponds to*/
  3242.                                                                                         /*    the menu's item number. This will    */
  3243.                                                                                         /*    bring the palette to the front.        */
  3244.             if (!WindowIsOpen(Poll.Menu.Item + VerticalPalette - 1)) /*If the specified    */
  3245.                 {                                                                        /*    palette is not open then display    */
  3246.                                                                                         /*    the palette…                                            */
  3247.                 switch (Poll.Menu.Item)                            /*Determine the item selected within    */
  3248.                     {                                                                    /*    this menu and open the specified    */
  3249.                     case 1:                                                        /*    palette window.                                        */
  3250.                         OpenDemoWindow10();                            /*                                                                        */
  3251.                         break;                                                    /*                                                                        */
  3252.                     case 2:                                                     /*                                                                        */
  3253.                         OpenDemoWindow11();                            /*                                                                        */
  3254.                         break;                                                    /*                                                                        */
  3255.                     }                                                                    /*                                                                        */
  3256.                 }                                                                        /*                                                                        */
  3257.             }                                                                            /*                                                                        */
  3258.             break;                                                                /*                                                                        */
  3259.         }
  3260.  
  3261.  
  3262.     if (!ExitTheDemo)                                                    /*If the user has not quit the app…        */
  3263.         MenuHilite(0);                                                    /*    turn off the highlighted menu in    */
  3264.                                                                                         /*    the menu bar.  This shows the user*/
  3265.                                                                                         /*    that the application has responded*/
  3266.     }                                                                                    /*    to the menu selection.                        */